public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* 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

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

On Tue, Sep 12, 2000 at 05:31:39PM -0400, Silvio Bandeira wrote:
> 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.

There is no 'clean' method of doing this.  In fact, many compilers offer no
means of overriding the default packing rules.  Also note, that you can't even
be guaranteed that an unsigned char is 8 bits (though it will be true in many
machines, but not all, including some machines that GCC targets).

-- 
Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482

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

* Re: data alignment
  2000-09-12 17:52 ` Michael Meissner
@ 2000-09-13 12:12   ` Silvio Bandeira
  0 siblings, 0 replies; 6+ messages in thread
From: Silvio Bandeira @ 2000-09-13 12:12 UTC (permalink / raw)
  To: gcc

Thanks for your reply.
Although there's no 'clean' method, do you know how can I make the
#pragma work?

I've seen some macros I could define but none of them work: here we go:
#define HANDLE_PRAGMA 1
#define HANDLE_SYSV_PRAGMA 1
#define BIGGEST_ALIGNMENT  8
#define BIGGEST_FIELD_ALIGNMENT  8
#define STRICT_ALIGNMENT 1

Michael Meissner wrote:

> There is no 'clean' method of doing this.  In fact, many compilers offer no
> means of overriding the default packing rules.  Also note, that you can't even
> be guaranteed that an unsigned char is 8 bits (though it will be true in many
> machines, but not all, including some machines that GCC targets).
>
> --
> Michael Meissner, Red Hat, Inc.
> PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
> Work:     meissner@redhat.com           phone: +1 978-486-9304
> Non-work: meissner@spectacle-pond.org   fax:   +1 978-692-4482

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

* Re: Data alignment
  2000-09-07  0:46 Data alignment Silvio Bandeira
@ 2000-09-07  9:57 ` David Edelsohn
  0 siblings, 0 replies; 6+ messages in thread
From: David Edelsohn @ 2000-09-07  9:57 UTC (permalink / raw)
  To: Silvio Bandeira; +Cc: gcc

>>>>> Silvio Bandeira writes:

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

	I do not belive that GCC has a commandline option equivalent to
IBM XLC's -qalign=packed which applies the alignment to all objects
automatically. 

David

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

* 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

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-12 13:33 data alignment Silvio Bandeira
2000-09-12 17:52 ` Michael Meissner
2000-09-13 12:12   ` Silvio Bandeira
  -- strict thread matches above, loose matches on Subject: below --
2000-09-13 21:24 Peeter Joot/Toronto/IBM
2000-09-07  0:46 Data alignment Silvio Bandeira
2000-09-07  9:57 ` David Edelsohn

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