Was ist der Unterschied zwischen sizeof und alignof?

Was ist der Unterschied zwischen sizeof und alignof?

#include <iostream>

#define SIZEOF_ALIGNOF(T) std::cout<< sizeof(T) << '/' << alignof(T) << std::endl

int main(int, char**)
{
        SIZEOF_ALIGNOF(unsigned char);
        SIZEOF_ALIGNOF(char);
        SIZEOF_ALIGNOF(unsigned short int);
        SIZEOF_ALIGNOF(short int);
        SIZEOF_ALIGNOF(unsigned int);
        SIZEOF_ALIGNOF(int);
        SIZEOF_ALIGNOF(float);
        SIZEOF_ALIGNOF(unsigned long int);
        SIZEOF_ALIGNOF(long int);
        SIZEOF_ALIGNOF(unsigned long long int);
        SIZEOF_ALIGNOF(long long int);
        SIZEOF_ALIGNOF(double);
}

Ausgabe

1/1
1/1
2/2
2/2
4/4
4/4
4/4
4/4
4/4
8/8
8/8
8/8

Denke ich, dass ich nicht das bekommen, was die Ausrichtung ist...?

InformationsquelleAutor user1494506 | 2012-07-08
Schreibe einen Kommentar