Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

__attribute__((packed)) in GCC is probably worth mentioning if you only want to apply it to selected structs.


#pragma pack(push)

#pragma pack(1)

MSVC


GCC also supports that pragma, for compatibility with MSVC:

http://gcc.gnu.org/onlinedocs/gcc/Structure-Packing-Pragmas....

Clang has this, too.


And MSVC doesn't support GCC's pragma, so for optimal portability #pragma pack(1) is my preferred way of doing it.


#pragma pack(push, 1) // :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: