pushpack1.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // ===============================================================================
  2. // May be included multiple times - sets structure packing to 1
  3. // for all supported compilers. #include <poppack1.h> reverts the changes.
  4. //
  5. // Currently this works on the following compilers:
  6. // MSVC 7,8,9
  7. // GCC
  8. // BORLAND (complains about 'pack state changed but not reverted', but works)
  9. // Clang
  10. //
  11. //
  12. // USAGE:
  13. //
  14. // struct StructToBePacked {
  15. // } PACK_STRUCT;
  16. //
  17. // ===============================================================================
  18. #ifdef AI_PUSHPACK_IS_DEFINED
  19. # error poppack1.h must be included after pushpack1.h
  20. #endif
  21. #if (defined(_MSC_VER) && !defined(__clang__)) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__)
  22. # pragma pack(push,1)
  23. # define PACK_STRUCT
  24. #elif defined( __GNUC__ ) || defined(__clang__)
  25. # if !defined(HOST_MINGW)
  26. # define PACK_STRUCT __attribute__((__packed__))
  27. # else
  28. # define PACK_STRUCT __attribute__((gcc_struct, __packed__))
  29. # endif
  30. #else
  31. # error Compiler not supported
  32. #endif
  33. #if defined(_MSC_VER)
  34. // C4103: Packing was changed after the inclusion of the header, probably missing #pragma pop
  35. # pragma warning (disable : 4103)
  36. #endif
  37. #define AI_PUSHPACK_IS_DEFINED