danmar/cppcheck — comment on commit df5d26901cabc0b64c96082dce39020ce5bc3617
File:  line 0
By edward-san:

Not one architecture. I added -Wpadded, then I tested it with and without -m32, and the result were the same.

I did some calculation. I'll report the token class as an example: since in the token class you're using only 3 pointers, 8 bools, 4 (unsigned) ints and a string, it's easy to calculate how aligned would it appear, independently from the architecture.

In fact, the only difference from x86 and x86-64 is the pointer which will be, respectively, 4-byte and 8-byte aligned. I don't know about std::string alignment, I suppose it's the same as a pointer, which still keep the alignment. This means the max alignment will be 4 bytes and 8 bytes, respectively.

In the 32 bit case, there was no difference before and after my commit, because int and void* are 4-bytes aligned, so there were no problems in alignment.

But in the 64 bit case, before my commit the pointers were between _varId and _fileIndex, which obliged the compiler to add 4 bytes between _varId and the first pointer so the struct had 4 excessive bytes. With my commit, the order of the variables are the following: 1 pointer(x3) + 8 bools + 2 ints(x2) + string => perfect match, no need to add bytes.

The data See also this article: http://www.codesynthesis.com/~boris/blog/2009/04/06/cxx-data-alignment-portability/