Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

vcgames

Problem on lesson31's source code

This topic is 5483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
#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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!