This is the mail archive of the gcc@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]

data alignment



>     I've used "__attribute__ ((packed))" after defining a struct, but it
> decreases portability.

Hi Silvio,

There is no such thing as "decreases portability" if you are delving into
the use of pragma's for packing or using __attribute__((packed)).  This is
an inherently unportable action, and if you do it you have to face the
consequences.

In fact it is a really really bad idea in general and will cause exceptions
(or real poor performance) on a number of platforms when the unaligned
members are accessed.  Unless you have a really good reason, just don't do
it.

Perhaps you can reorder your structure to fix the alignment problems.  What
specific reason do you need a packed structure?  Another options is
treating the memory in a raw format and doing bytewise copies in and out of
the structure -- that is probably as close to portable you are going to get
(if you are careful).

Peeter



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