Jump to content
  • Advertisement

Archived

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

Can someone explain this code?

This topic is 6303 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

#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''m writing a milkshape model loader and I had problem with loading the number of vertices which was saved as a word(unsigned short, right?) However it didnt work, I just got a number which was totally wrong, until I found this code in PortaLib3D at http://rsn.gamedev.net. Can someone explain what this code does since I have no idea... Thanks...

Share this post


Link to post
Share on other sites
Advertisement
It is checking the ''struct member alignment'' settings of the compiler.

With MS Visual C++, go to; Project -> Settings -> C/C++, Code Generation and set ''struct member alignment'' to 1 byte.

Structs that are not aligned according to this setting are padded with null bytes by the compiler so you will have problems with reading non-aligned structs from a file. This is why you get unexpected readings for values like ''no. of vertices''.

Cheers

Matt



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!