This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Data alignment with gcc


>-----Original Message-----
>From: Lewin A.R.W. Edwards [mailto:larwe@larwe.com]
>Sent: 30 March 2001 04:00

>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 :) 

  As long as the class doesn't use virtual inheritance or virtual
functions, there should be no additional data hidden in the struct IIRC.
C++ isn't all that uncommon in embedded work but you do need to have
some idea what's going on behind the scenes, particularly once you
start using overloaded operators and temporary objects, or you can lose
loads of performance copying class objects from place to place.

>// 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.

  I have sometimes heard it said that the __attribute__ ((packed)) needs
to be put on the data members of a struct as well, i.e.

>typedef struct {
>         unsigned char fill[0x1be] __attribute__((packed));
>         PARTENTRY partitions[4] __attribute__((packed));
>         unsigned char sig_55 __attribute__((packed));
>         unsigned char sig_aa __attribute__((packed));
>} __attribute__((packed)) MBR, *PMBR;

but I haven't tested this so YMMV.

       DaveK
-- 
 All your base are belong to us!


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]