
Keith B. answered 09/20/19
Software Engineer and Math Geek
If you're adding up the members and comparing the results to sizeof() and finding a difference, the problem most likely is with byte alignment - how much is it off by? Do you have character arrays in your structure, and do they have an odd number for a length? Compilers will often add a space between the members to have the bytes being used fall on an even alignment.
Another issue could be that you are not adding the sizes manually correctly, that the machine's size for a type is different than what you think it might be. Try printing the sizeof() for the individual elements of the structure, and see if those add up to the size of the whole structure.
Look into #pragma pack if you need to force the alignment.