Problem on lesson31's source code
In the file MilkShapeModel.cpp there are there codes:
#ifdef _MSC_VER
# pragma pack( push, packing )
# pragma pack( 1 )
# define PACK_STRUCT
#elif defined( __GNUC__ )
# define PACK_STRUCT __attribute__((packed))
#else
# error you must byte-align these structures with the appropriate compiler directives
#endif
I am not familiar with these codes and I want to know the meaning of every line.Would you please tell me the use of them?
Thanks in advance.
#ifdef _MSC_VER // If compiler is MSVC
# pragma pack( push, packing ) // Toggle byte alignment
# pragma pack( 1 ) // ...
# define PACK_STRUCT // Define the macro PACK_STRUCT to be nothing
#elif defined( __GNUC__ ) // If compiler is GNU C
# define PACK_STRUCT __attribute__((packed)) // Define the macro
#else // Otherwise we dont know which compiler we''re using
# error you must byte-align these structures with the appropriate compiler directives
#endif // Done
So basically, we have the macro PACK_STRUCT. The idea is that this preprocess code is cross compiler compatible and to that end we either define the macro to be something or nothing depending on whether we''re using a compiler such as the GNU C compiler which requires the use of a keyword to perform byte alignment on the structures, or whether we''re using MSVC which does not have an equivalent keyword, but rather requires some #pragma precompiler directives.
Check your compiler documentation.
# pragma pack( push, packing ) // Toggle byte alignment
# pragma pack( 1 ) // ...
# define PACK_STRUCT // Define the macro PACK_STRUCT to be nothing
#elif defined( __GNUC__ ) // If compiler is GNU C
# define PACK_STRUCT __attribute__((packed)) // Define the macro
#else // Otherwise we dont know which compiler we''re using
# error you must byte-align these structures with the appropriate compiler directives
#endif // Done
So basically, we have the macro PACK_STRUCT. The idea is that this preprocess code is cross compiler compatible and to that end we either define the macro to be something or nothing depending on whether we''re using a compiler such as the GNU C compiler which requires the use of a keyword to perform byte alignment on the structures, or whether we''re using MSVC which does not have an equivalent keyword, but rather requires some #pragma precompiler directives.
Check your compiler documentation.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement