Good example
For example, here's how you'd ensure that a structure is packed tightly (i.e. no padding between members) in MSVC:
#pragma pack(push, 1)struct PackedStructure{ char a; int b; short c;};#pragma pack(pop)// sizeof(PackedStructure) == 7Here's how you'd do the same thing in GCC:
struct PackedStructure __attribute__((__packed__)){ char a; int b; short c;};// sizeof(PackedStructure == 7)The GCC code is more portable, because if you want to compile that with a non-GCC compiler, all you have to do is
#define __attribute__(x)
Whereas if you want to port the MSVC code, you have to surround each pragma with a #if/#endif pair. Not pretty.
No comments:
Post a Comment