Can I assume sizeof(GUID)==16 at all times?

Viewed 10667

The definition of GUID in the windows header's is like this:

typedef struct _GUID {
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[ 8 ];
} GUID;

However, no packing is not defined. Since the alignment of structure members is dependent on the compiler implementation one could think this structure could be longer than 16 bytes in size.

If i can assume it is always 16 bytes - my code using GUIDs is more efficient and simple. However, it would be completely unsafe - if a compiler adds some padding in between of the members for some reason.

My questions do potential reasons exist ? Or is the probability of the scenario that sizeof(GUID)!=16 actually really 0.

6 Answers
Related