"lang_statement_union_type and its usage?"
Ian Lance Taylor
ian@zembu.com
Thu May 31 12:11:00 GMT 2001
xinant@cognigine.com (Xinan Tang) writes:
> In ld/ldlang.h, lang_statement_union_type is defined as:
>
> typedef union lang_statement_union
> {
> lang_statement_header_type header;
> union lang_statement_union *next;
> ... /* Other stuffs */
> } lang_statement_union_type;
>
>
> However, I saw in many places in `ldlang.c', the list is traversed as
> follows:
>
> for (; s != (lang_statement_union_type *) NULL; s = s->next)
> {
> switch (s->header.type)
> ...
> }
>
> The question is that the 'next' and 'header' fields are exclusive, how
> could they be used at the same time. Could some one inlight me why
> this usage is SAFE?
>
> My goal is to traverse the statement list at the linking time. I have
> difficulty to understand why the list is searched in this way.
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
More information about the Binutils
mailing list