Is sizeof(T) == sizeof(int)?

前端 未结 3 972
南方客
南方客 2021-01-04 09:16

I\'ve been poring over the draft standard and can\'t seem to find what I\'m looking for.

If I have a standard-layout type

struct T {
   unsigned hand         


        
3条回答
  •  青春惊慌失措
    2021-01-04 09:37

    I am used to Borland environments and for them:

    T is a struct in your case so sizeof(T) is size of struct

    • that depends on #pragma pack and align setting of your compiler
    • so sometimes it can be greater than sizeof(unsigned) !!!

    for the same reason if you have 4Byte struct (uint32) and 16Byte allign

    • struct T { uint32 u; };
    • then T a[100] is not the same as uint32 a[100];
    • because T is uint32 + 12 Byte empty space !!!

提交回复
热议问题