Struct Alignment elements in Visual C ++ 2008

Visual C ++ allows you to select struct alignemnt elements on the project properties page. The problem is that this configuration is used for all srtructs in the project.

Is there any way (perhaps, VC ++, I would guess) to set the alignment of the individual structure elements separately?

+3
source share
3 answers
+1
source

for really specific alignments of the structure, you can play with fill bytes

So, add a few dummy bytes between the various fields until the alignment suits your needs.

Example:

Example

struct {unsigned short x; byte dummy1; dummy2 byte dummy3 byte byte dummy4; dummy5 byte byte dummy6; unsigned int y; };

if the dummy bytes have not been placed, int, probably would have been a displacement of 4 (4 bytes from the beginning of the structure, and now he was placed with an offset 8)

waring: very specific compiler and bad code, ^)

0
source

All Articles