From: Ian Lance Taylor <ian@zembu.com>
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 12:11:00 -0000 [thread overview]
Message-ID: <siae3tnxlt.fsf@daffy.airs.com> (raw)
In-Reply-To: <3B169422.8090300@cognigine.com>
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
next prev parent reply other threads:[~2001-05-31 12:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-05-31 11:57 Xinan Tang
2001-05-31 12:11 ` Ian Lance Taylor [this message]
2001-05-31 13:47 ` Xinan Tang
2001-05-31 13:56 ` Geoff Keating
2001-05-31 14:10 ` Ian Lance Taylor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=siae3tnxlt.fsf@daffy.airs.com \
--to=ian@zembu.com \
--cc=binutils@sources.redhat.com \
--cc=xinant@cognigine.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).