On Sat, 24 Jun 2000, Xuan Baldauf wrote:
> > Are you saying that:
> > struct foo
> > {
> > int x;
> > int y;
> > } bar;
> >
> > ((int *)&bar + 1) != &bar.y
> >
> > can sometimes be true?
>
> I suspect this will always be true, at least unless x is not of type char...
can you point to a place in K&R or ANSI C that says so?
K&R says (page 213, A8.3):
Adjacent field members of structures are packed into
implementation-dependent storage units in an implementation-dependent
direction. ... The members of a structure have addresses increasing in
the order of their declaration.
I think Alan Cox is right - there is no guarantee that field members of a
structure can be found one after another starting from the first field.
But the first field can always be found from the address of the structure
itself, as K&R says:
If a pointer to a structure is cast to the type of a pointer to its
first member, the result refers to the first member.
Regards,
Tigran
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Mon Jun 26 2000 - 21:00:04 EST