public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Dan Nicolaescu <dann@godzilla.ICS.UCI.EDU>
To: mike stump <mrs@windriver.com>
Cc: jason@redhat.com, gcc@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: C++ aliasing rules
Date: Wed, 24 Apr 2002 13:32:00 -0000	[thread overview]
Message-ID: <200204241327.aa13343@gremlin-relay.ics.uci.edu> (raw)
In-Reply-To: <200204240235.TAA23236@kankakee.wrs.com>

mike stump <mrs@windriver.com> writes:

  > > To: Dan Nicolaescu <dann@godzilla.ICS.UCI.EDU>
  > > Cc: libstdc++@gcc.gnu.org, gcc@gcc.gnu.org
  > > From: Jason Merrill <jason@redhat.com>
  > > Date: Tue, 23 Apr 2002 10:43:27 +0100
  > 
  > > > struct first  {  int i; char a;  int f1;  char f2; double d;};
  > > > struct second {  char b;  int f2;  int f3;};
  > 
  > > > can it be assumed that given that "first" and "second" are
  > > > incompatible then ps1.f1 and ps2.f2 don't alias
  > 
  > This would be an excellent question for comp.std.c.  C++ mostly just
  > followed C on this. 

As a matter of fact I asked this question on comp.std.c sometime in
March. And the answer was that the C standard is a bit unclear in this
area...  

  >  We fixed a few things (made memcpy so that it can
  > be portably written within the rules of the language), but it should
  > mostly be the same.  You would need complete code, and might need to
  > `fix up' the example so that you can have them answer the question you
  > wanted.

A bit too much of my original post was snipped in the message you
replied to, that's why the code is incomplete, see:

http://gcc.gnu.org/ml/libstdc++/2002-04/msg00049.html


  > Consider:
  > 
  > struct { char buf[sizeof (double)]; short i; } secondo, *second = &secondo;
  > struct { double other; short i; } firsto, *not_really_first = &secondo;
  > 
  > and the question of whether or not first->i can ever alias second->i.
  > 
  > I suspect the closest we can come would be to
  > 
  >   memcpy (&secondo, &firsto, sizeof (secondo));
  > 
  > and then play with not_really_first->i and second->i.
  > 
  > I think the answer is no, as no matter what you do, you need to
  > violate the notion of which struct type the object really was and you
  > cannot get at the short without going though the struct first, and in
  > the end, you cannot get through both struct types simultaneously.

I like this answer. :-) 

Does anybody disagree with Mike's statement above (wrt C++) ? Jason? 


  > No, before you implement this, you need to be aware that some
  > prefixing is probably ok:

I've already implemented it. 
I have an unsubmited patch that takes care of the prefixing thing
too. I'll reopen the discussion on the patches after 3.1 is released,
if we have an agreement that it's OK from the C++ standard point of
view. 

BTW, there's a defect report for C99 that says that allowing prefixing
is not such a great idea...

Thanks.
                --dan

  parent reply	other threads:[~2002-04-24 20:27 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
2002-04-24 13:32     ` Dan Nicolaescu [this message]
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=200204241327.aa13343@gremlin-relay.ics.uci.edu \
    --to=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).