From: Andreas Schwab <schwab@suse.de>
To: mike stump <mrs@windriver.com>
Cc: dann@godzilla.ICS.UCI.EDU, jason@redhat.com, gcc@gcc.gnu.org,
libstdc++@gcc.gnu.org
Subject: Re: C++ aliasing rules
Date: Wed, 24 Apr 2002 06:43:00 -0000 [thread overview]
Message-ID: <jewuux43rx.fsf@sykes.suse.de> (raw)
In-Reply-To: <200204240235.TAA23236@kankakee.wrs.com> (mike stump's message of "Tue, 23 Apr 2002 19:35:47 -0700 (PDT)")
mike stump <mrs@windriver.com> writes:
|> No, before you implement this, you need to be aware that some
|> prefixing is probably ok:
|>
|> 6.3.2.3 Structure and union members
FYI, this is how the section reads in the final standard. Especially
[#5] is different and there is one more example.
6.5.2.3 Structure and union members
Constraints
[#1] The first operand of the . operator shall have a qualified or
unqualified structure or union type, and the second operand shall name a
member of that type.
[#2] The first operand of the -> operator shall have type pointer to
qualified or unqualified structure or pointer to qualified or unqualified
union, and the second operand shall name a member of the type pointed to.
Semantics
[#3] A postfix expression followed by the . operator and an identifier
designates a member of a structure or union object. The value is that of
the named member, and is an lvalue if the first expression is an
lvalue. If the first expression has qualified type, the result has the
so-qualified version of the type of the designated member.
[#4] A postfix expression followed by the -> operator and an identifier
designates a member of a structure or union object. The value is that of
the named member of the object to which the first expression points, and
is an lvalue.79) If the first expression is a pointer to a qualified
type, the result has the so-qualified version of the type of the
designated member.
[#5] One special guarantee is made in order to simplify the use of
unions: if a union contains several structures that share a common
initial sequence (see below), and if the union object currently contains
one of these structures, it is permitted to inspect the common initial
part of any of them anywhere that a declaration of the complete type of
the union is visible. Two structures share a common initial sequence if
corresponding members have compatible types (and, for bit-fields, the
same widths) for a sequence of one or more initial members.
[#6] EXAMPLE 1 If f is a function returning a structure or union, and x
is a member of that structure or union, f().x is a valid postfix
expression but is not an lvalue.
[#7] EXAMPLE 2 In:
struct s { int i; const int ci; };
struct s s;
const struct s cs;
volatile struct s vs;
the various members have the types:
s.i int
s.ci const int
cs.i const int
cs.ci const int
vs.i volatile int
vs.ci volatile const int
[#8] EXAMPLE 3 The following is a valid fragment:
union {
struct {
int alltypes;
} n;
struct {
int type;
int intnode;
} ni;
struct {
int type;
double doublenode;
} nf;
} u;
u.nf.type = 1;
u.nf.doublenode = 3.14;
/* ... */
if (u.n.alltypes == 1)
if (sin(u.nf.doublenode) == 0.0)
/* ... */
The following is not a valid fragment (because the union type is not
visible within function f):
struct t1 { int m; };
struct t2 { int m; };
int f(struct t1 * p1, struct t2 * p2)
{
if (p1->m < 0)
p2->m = -p2->m;
return p1->m;
}
int g()
{
union {
struct t1 s1;
struct t2 s2;
} u;
/* ... */
return f(&u.s1, &u.s2);
}
Forward references: address and indirection operators (6.5.3.2),
structure and union specifiers (6.7.2.1).
--------------------
79) If &E is a valid pointer expression (where & is the address-of
operator, which generates a pointer to its operand), the expression
(&E)->MOS is the same as E.MOS.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
next prev parent reply other threads:[~2002-04-24 13:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <200204031103.aa15838@gremlin-relay.ics.uci.edu>
2002-04-23 13:59 ` Jason Merrill
2002-04-23 19:52 ` mike stump
2002-04-24 6:43 ` Andreas Schwab [this message]
2002-04-24 13:32 ` Dan Nicolaescu
2002-04-25 1:11 ` Nathan Sidwell
2002-04-25 10:57 ` Jason Merrill
2002-04-25 17:44 ` mike stump
2002-05-17 13:09 ` Dan Nicolaescu
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=jewuux43rx.fsf@sykes.suse.de \
--to=schwab@suse.de \
--cc=dann@godzilla.ICS.UCI.EDU \
--cc=gcc@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=libstdc++@gcc.gnu.org \
--cc=mrs@windriver.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).