What does the warning “alignment of a member was sensitive to packing” mean in C++? I’m using Visual Studio 2005.
How do I go about removing these warnings? I don’t want to disable them btw.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Some data types must be aligned to a certain boundary. So for example:
sizeof(char) is 1 and sizeof(double) is 8 but the size of that struct may be more than the expected 18 if it needs the doubles to align to an 8-byte boundary. In that case, and because the members should appear in memory in the order they are declared in the struct, there may be 7 bytes of “padding” close to the member c, and possibly some with member a too.
The danger here comes when the packing is non-standard so the size of this struct could vary, and you send it in “binary” format over a wire or store it in a file where it will be read elsewhere (even if the endian-ness of the double is the same).
As an alternative to the suggestions to remove the warning through pragmas, you might decide to deal with it in the code by changing the order of your members. Put those that need the biggest alignment first, and the lower ones later. So first put pointers and doubles, then ints, then shorts and any char members last.