public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Data alignment
@ 2000-09-07  0:46 Silvio Bandeira
  2000-09-07  9:57 ` David Edelsohn
  0 siblings, 1 reply; 6+ messages in thread
From: Silvio Bandeira @ 2000-09-07  0:46 UTC (permalink / raw)
  To: gcc

Hi,

   I'm using gcc in a AIX 4.2.1 box and I'd like to know if there's an 
option to tell the compiler I want all my data aligned with 1 byte 
boundary. I saw the "packed" attribute in gcc manual, but I'd find it 
more simple and portable if I didn't need to put it hardwared in the code.

   Thanks in advance for any information.

   Best regards.

--
Silvio Bandeira
UNICAP - Dept. of Computer Science

^ permalink raw reply	[flat|nested] 6+ messages in thread
* data alignment
@ 2000-09-12 13:33 Silvio Bandeira
  2000-09-12 17:52 ` Michael Meissner
  0 siblings, 1 reply; 6+ messages in thread
From: Silvio Bandeira @ 2000-09-12 13:33 UTC (permalink / raw)
  To: gcc

Hi guys,

    Do you know how to control arrays and structures alignment using gcc
? I need them "packed".
    I've used "__attribute__ ((packed))" after defining a struct, but it
decreases portability. Is there a more "clean" way to specify that for
all data structures?
    I've also tried "#pragma pack(1)" but gcc says "ignoring pragma".
    Thanks in advance for any information.

--
Silvio Bandeira
UNICAP - Dept. of Computer Science



^ permalink raw reply	[flat|nested] 6+ messages in thread
* data alignment
@ 2000-09-13 21:24 Peeter Joot/Toronto/IBM
  0 siblings, 0 replies; 6+ messages in thread
From: Peeter Joot/Toronto/IBM @ 2000-09-13 21:24 UTC (permalink / raw)
  To: Silvio Bandeira; +Cc: gcc

>     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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-09-13 21:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-07  0:46 Data alignment Silvio Bandeira
2000-09-07  9:57 ` David Edelsohn
2000-09-12 13:33 data alignment Silvio Bandeira
2000-09-12 17:52 ` Michael Meissner
2000-09-13 12:12   ` Silvio Bandeira
2000-09-13 21:24 Peeter Joot/Toronto/IBM

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).