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 14:10:00 -0000 [thread overview]
Message-ID: <si4ru1mdjn.fsf@daffy.airs.com> (raw)
In-Reply-To: <3B16ADDC.80700@cognigine.com>
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
prev parent reply other threads:[~2001-05-31 14:10 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
2001-05-31 13:47 ` Xinan Tang
2001-05-31 13:56 ` Geoff Keating
2001-05-31 14:10 ` Ian Lance Taylor [this message]
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=si4ru1mdjn.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).