This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: "lang_statement_union_type and its usage?"
xinant@cognigine.com (Xinan Tang) writes:
> > All elements of lang_statement_union start with
> > lang_statement_header_type header;
> > The first field in lang_statement_header_type is
> > union lang_statement_union *next;
> > Therefore, in all cases, the first field in any instance of
> > lang_statement_union will be the next pointer.
> > This is a pretty common hack when implementing derived classes in C.
> > Ian
>
> I see. However, this may not work if some optimizing compilers
> would change the relative order of the `next' field. I.e., this scheme
> is compiler-dependent.
The ISO C standard forbids compilers from making the possible
optimization. ISO C requires that structure members have addresses
that increase in the order in which they are declared. ISO C also
says ``a pointer to a structure object, suitably converted, points to
its initial member'' and ``a pointer to a union object, suitably
converted, points to each of its members.''
This is required in order to make it possible for a C structure or
union to describe an area of memory used by hardware, a traditional
use of C in kernel driver implementations.
C is not a high level language.
Ian