Skip to main content
gamedev.net
🔒 Locked

strange struct size

Started by smokes 0 replies 150+ views
Original Post
smokes
smokes
struct something { char number1; unsigned short number2; }; sizeof(something) = 4 why is this true? I mean a char is one byte and an unsigned short is a word, that is 2 bytes.. therefore the size should be 3 bytes.. but in Visual c++ 6 it is 4..
Beer Hunter
Beer Hunter
The compiler added in an extra byte for performance reasons.

If you want to prevent that, MSVC provides this way:

  
#pragma pack(push, 1)
struct something {
...
};
#pragma pack(pop)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.