public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bernhard Fischer <rep.nop@aon.at>
To: gcc-help@gcc.gnu.org
Cc: Bernhard Fischer <rep.nop@aon.at>
Subject: gcc-head bug? feature?
Date: Sun, 02 Oct 2005 00:21:00 -0000	[thread overview]
Message-ID: <20051001235622.GW8756@aon.at> (raw)

[please keep me CC'd]
Hi,

Is this a user error (thus an optimisation feature) or a glitch in gcc?

$ for o in '' -O2; do echo "# o='$o'";gcc-4.1-HEAD -W -Wall -Wextra
-pedantic $o -g -Wall -I. -o bar41.$o foo.c ;./bar41.$o;done
# o=''
var1=1020308
var1=1020809
# o='-O2'
foo.c: In function 'main':
foo.c:7: warning: dereferencing type-punned pointer will break
strict-aliasing rules
var1=1020308
var1=1020308

with O2, the second assignment is "optimized out"?

gcc-4.0.1, gcc-3.4, gcc-3.3, gcc-2.95 all yield 1020308 and 1020809 for
Odefault and O2, as opposed to gcc-4.1.

$ cat foo.c 
#include <stdio.h>
int main(void)
{
	int var1 = 0x01020304;
	*(char *)&var1 = 0x08;
	printf("var1=%x\n", var1);
	*(short *)&var1 = 0x0809;
	printf("var1=%x\n", var1);
	return 0;
}

             reply	other threads:[~2005-10-02  0:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-02  0:21 Bernhard Fischer [this message]
2005-10-02  1:03 Ryan Mansfield

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=20051001235622.GW8756@aon.at \
    --to=rep.nop@aon.at \
    --cc=gcc-help@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).