From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Lance Taylor To: xinant@cognigine.com (Xinan Tang) Cc: binutils@sources.redhat.com Subject: Re: "lang_statement_union_type and its usage?" Date: Thu, 31 May 2001 14:10:00 -0000 Message-id: References: <3B169422.8090300@cognigine.com> <3B16ADDC.80700@cognigine.com> X-SW-Source: 2001-05/msg00563.html 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