This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
data alignment
- To: Silvio Bandeira <silvio at dei dot unicap dot br>
- Subject: data alignment
- From: "Peeter Joot/Toronto/IBM" <peeterj at ca dot ibm dot com>
- Date: Thu, 14 Sep 2000 00:21:21 -0400
- Cc: gcc <gcc at gcc dot gnu dot org>
> 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