lkml.org 
[lkml]   [2004]   [Jun]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: drivers/block/ub.c
On Mon, 28 Jun 2004 17:18:57 -0400
Scott Wood <scott@timesys.com> wrote:

> On Mon, Jun 28, 2004 at 02:03:43PM -0700, David S. Miller wrote:
> > You have not considered what is supposed to happen when this
> > structure is embedded within another one. What kind of alignment
> > rules apply in that case? For example:
> >
> > struct foo {
> > u32 x;
> > u8 y;
> > u16 z;
> > } __attribute__((__packed__));
> >
> > struct bar {
> > u8 a;
> > struct foo b;
> > };
>
> As long as bar is not packed, why shouldn't the beginning of bar.b be
> aligned?

No! bar.b starts at offset 1 byte. That's how this stuff works.

This is exactly why you cannot assume the alignment of any structure
which is given attribute __packed__. The example above shows that
quite clearly.

Try it out if you don't believe someone who has maintained the
Linux networking for 7 years and sits on the GCC Steering Committee.
:-)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:04    [W:0.221 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site