Re: [patch-2.4.0-test2]Re: Linux-2.4.0-test2

From: Xuan Baldauf (xuan--reiserfs@baldauf.org)
Date: Sat Jun 24 2000 - 11:37:16 EST


Tigran Aivazian wrote:

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

Currently, I have no reference (but common sense), but AFAIK "+1" means "increment
the pointer by 1 (byte)", not "increment the pointer by one storage unit (4
bytes)".

However, I suspect something like "&(((int *)&bar)[1]) != &bar.y" or "((int *)&bar
+ 4) != &bar.y" was your question.

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

IIRC there are dozens of structs shared between userspace and kernel space. Does
that mean that all those structs are strictly speaking incompatible with each
other, given that the compiler or CFLAGS are different?

>
>
> Regards,
> Tigran

Xuân. :o)

-
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