public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Geoff Keating <geoffk@geoffk.org>
To: Bruce Korb <bkorb@pacbell.net>
Cc: gcc@gcc.gnu.org
Subject: Re: module level flags
Date: Sun, 29 Sep 2002 15:46:00 -0000	[thread overview]
Message-ID: <jmlm5kv4yv.fsf@desire.geoffk.org> (raw)
In-Reply-To: <3D965678.DF33B8BB@pacbell.net>

Bruce Korb <bkorb@pacbell.net> writes:

> Zack Weinberg wrote:
> 
> > I'm afraid the compiler is working as designed.
> > 
> > >          YYSTYPE  def,
> > >          YYSTYPE  list )
> > >  {
> > > +    tDefEntry*  ret   = (tDefEntry*)list;
> > >      tDefEntry*  pDef  = (tDefEntry*)def;
> > > -    tDefEntry*  pScn  = (tDefEntry*)list;
> > > -    tDefEntry** ppT   = (tDefEntry**)&list;
> > > +    tDefEntry*  pScn  = ret;
> > > +    tDefEntry** ppT   = &ret;
> > 
> > In the original code, the type-based aliasing rules permit the
> > compiler to assume that assignment to ppT does not modify list
> > EVEN THOUGH IT IS OBVIOUS TO A HUMAN THAT IT DOES.
> > 
> > Your fix is the right way to correct your code.  By immediately
> > assigning list to a temporary with its true type, you show the
> > compiler what's really going on.
> 
> That is completely goofy.  Is that really the intent of the
> official standard, or GCC's interpretation?

Yes, that's the intent of the official standard.

There's no guarantee that two pointers to different types have the
same representation.  For instance, if you have

tDefEntry foo;
void *x;

*(tDefEntry **)&x = &foo;
if (x != (void *)&foo)
  abort();

this could call abort, or do anything else (since it invokes undefined
behavior).

In fact, there's no guarantee even that 'sizeof (void *)' is the same
as 'sizeof (tDefEntry *)'.

-- 
- Geoffrey Keating <geoffk@geoffk.org>

  reply	other threads:[~2002-09-29 21:52 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-28 16:41 Bruce Korb
2002-09-28 16:52 ` Tim Prince
2002-09-28 16:53   ` Bruce Korb
2002-09-28 18:06     ` Zack Weinberg
2002-09-28 18:20       ` Bruce Korb
2002-09-28 20:56         ` Zack Weinberg
2002-09-28 22:08           ` Bruce Korb
2002-09-29 15:46             ` Geoff Keating [this message]
2002-09-29  3:20       ` Robert Dewar
2002-09-29 11:55         ` Zack Weinberg
2002-09-29 13:10           ` Bruce Korb
2002-09-29 13:59             ` Zack Weinberg
2002-09-29 17:21     ` Tom Tromey
2002-09-29  6:40 Robert Dewar
2002-09-29 10:05 ` Bruce Korb
2002-09-29 10:17   ` Gabriel Dos Reis
2002-09-29 10:45     ` Bruce Korb
2002-09-29 11:36       ` Gabriel Dos Reis
2002-09-29 13:06       ` Daniel Jacobowitz
2002-09-29 13:08         ` Bruce Korb
2002-09-29 13:21           ` Daniel Jacobowitz
2002-09-29 10:49   ` Russ Allbery
2002-09-30 21:33   ` Alexandre Oliva
2002-09-30 21:42     ` Bruce Korb
2002-09-29 10:31 Robert Dewar
2002-09-29 10:45 Robert Dewar
2002-09-29 13:36 Robert Dewar
2002-09-29 13:38 ` Bruce Korb
2002-09-29 14:05   ` Russ Allbery
2002-09-29 13:38 Robert Dewar
2002-09-29 13:42 Robert Dewar
2002-09-29 14:52 ` Russ Allbery
2002-09-29 14:03 Robert Dewar
     [not found] <orn0py67ug.fsf@free.redhat.lsd.ic.unicamp.br>
2002-10-01 11:33 ` Joe Buck
2002-10-01 12:16   ` Geoff Keating
2002-10-05 21:03     ` Kai Henningsen
2002-10-06  6:36       ` Gabriel Dos Reis
2002-10-06  8:25         ` Nathan Sidwell
2002-10-06  8:29           ` Gabriel Dos Reis
2002-10-01 12:29   ` Bruce Korb
2002-10-01 14:14     ` Alexandre Oliva
2002-10-01 14:25   ` Alexandre Oliva
2002-10-03 16:46     ` Joe Buck
2002-10-03 17:34       ` Zack Weinberg
2002-10-03 18:07         ` Richard Henderson
2002-10-01 13:58 Robert Dewar
2002-10-01 14:54 ` Joe Buck
2002-10-01 15:40   ` Michael Matz
2002-10-05 11:36 ` Toon Moene
2002-10-02  0:53 Robert Dewar

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=jmlm5kv4yv.fsf@desire.geoffk.org \
    --to=geoffk@geoffk.org \
    --cc=bkorb@pacbell.net \
    --cc=gcc@gcc.gnu.org \
    /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).