Data alignment with gcc

Lewin A.R.W. Edwards larwe@larwe.com
Thu Mar 29 19:33:00 GMT 2001


>For reasons that I won't go into to keep this mail brief, it is essential
>that the class data members are in the order given above and most
>importantly *NOT* aligned to word boundaries. (essentially, an object is

Very common requirement for embedded systems and device drivers, at least 
for structures. I don't know about C++ classes (embedded work in C++ is 
relatively rare...  and there are a lot of hidden implicit things in a C++ 
class :) But for structures, the following is an illustration of the 
correct syntax:

// Master Boot Record
typedef struct {
         unsigned char fill[0x1be];      // boot code
         PARTENTRY partitions[4];        // partition table
         unsigned char sig_55;           // 55h boot signature
         unsigned char sig_aa;           // AAh boot signature
} __attribute__((packed)) MBR, *PMBR;

Works in 2.95.2.

=== Lewin A.R.W. Edwards (Embedded Engineer)
Work: http://www.digi-frame.com/
Personal: http://www.zws.com/ and http://www.larwe.com/

"Und setzet ihr nicht das Leben ein,
Nie wird euch das Leben gewonnen sein."



More information about the Gcc-help mailing list