Bug#442854: hex-a-hop: [m68k] FTBFS: packfile.h:57: error: size of array 'static_assert1' is negative

Geert Uytterhoeven geert at linux-m68k.org
Wed Sep 19 14:05:53 UTC 2007


On Wed, 19 Sep 2007, Jens Seidel wrote:
> On Wed, Sep 19, 2007 at 09:03:18AM +0200, Geert Uytterhoeven wrote:
> > On Wed, 19 Sep 2007, Jens Seidel wrote:
> > > Nevertheless I'm nearly sure that this platform doesn't align a char[1]
> > > array on 64 bit boundaries so the code should work :-)
> > 
> > > typedef struct Entry {
> > >   int32_t len;
> > >   // could there be an alignment gap here?
> > >   char name[1];
> > > } Entry;
> > 
> > On m68k, 32-bit quantities must be aligned to 2 bytes.
> > Since sizeof() of a struct always gives a value that's a multiple of the
> > maximum alignment of the individual fields of the struct, you get 6 (5
> > rounded up to a multiple of 2).
> 
> Thanks, I assumed this after getting the error.
> 
> A not m68k related question:
> 
> Is it OK to interpret a random char pointer as Entry* or need this data
> be on an even adress? Will do following work (is used by the program this
> way!):
> 
> char tmp[10];
> 
> Entry *e0 = (Entry*)&tmp[0];
> Entry *e1 = (Entry*)&tmp[1];
> 
> Either &tmp[0] or &tmp[1] is not an even address.

For m68k, this will work on MC68020 and higher.
But in general, it will cause alignment exceptions on many RISC
architectures.

You can hint gcc that unaligned accesses may happen by adding
`attribute ((packed))' to the struct definition. But this will generate
slower code on many platforms, as gcc will assume all accesses can be
unaligned. Note that `sizeof(Entry)' will become 5. If you want it to
stay 8, you have to add explicit padding.

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds





More information about the Pkg-games-devel mailing list