Jump to content
  • Advertisement


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


Can someone explain this code?

This topic is 6481 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))
#	error you must byte-align these structures with the appropriate compiler directives
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
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''.



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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!