C++ Data Member Alignment and Array Packing
问题 During a code review I've come across some code that defines a simple structure as follows: class foo { unsigned char a; unsigned char b; unsigned char c; } Elsewhere, an array of these objects is defined: foo listOfFoos[SOME_NUM]; Later, the structures are raw-copied into a buffer: memcpy(pBuff,listOfFoos,3*SOME_NUM); This code relies on the assumptions that: a.) The size of foo is 3, and no padding is applied, and b.) An array of these objects is packed with no padding between them. I've