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]

Re: attribute ((packed)) on variables


On Thu, Apr 13, 2000 at 12:08:35PM +0200, Christian Häggström wrote:
> Thanks for your answer.
> 
> >... whether it defines MAX_OFILE_ALIGNMENT or not.
> 
> But I think you misunderstood me, I was asking for the minimum alignment, not the maximum. I wanted to make 'name' not aligned at all:
>   char name[33] __attribute__((aligned(1)));
> This doesn t work. The manual says alignment can only be increased with this attribute.
>   char name[33] __attribute__((packed));
> This should work (according to manual). But gcc says "warning: attribute 'packed' ignored"
> 
> Is there any way to misalign objects larger than 32 byte?

Not in 2.95.2.  If you download the current snapshot it will work (modulo the
usual disclaimer that snapshots are out there for testing, and may not work for
a given target).

> >> I use gcc 2.95.2 on a pentium.
> 
> >(you didn't mention the OS, which is crucial in this case, since each OS or
> >object file format could define the macro or not).
> >elf systems (ie,Linux) did not define MAX_OFILE_ALIGNMENT in 2.95, but do define it in the current snapshot.
>
> Yes, you guess right, I use Linux. The object format doesn t matter as I
> convert it to binary format to use it for boot disks.

Actually, object format does matter.  Even with the current snapshot, selecting
the a.out object file format (ie, i686-linux-gnuaout or i686-linux-gnuoldld)
means you are limited to aligning things to a 32-bit (4 byte) alignment.  This
is because the a.out object format has no way of specifying alignment (hey, it
was the state of the art in 1969 for the Ritchie compiler :-).  If you select
the elf object file format and use the current snapshots, then you can align
things to an arbitrary power of 2 alignment.

-- 
Michael Meissner, Cygnus Solutions, a Red Hat company.
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

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