From: Andrew Haley <aph@redhat.com>
To: David Daney <ddaney@caviumnetworks.com>
Cc: Honggang Xu <hxu@zeugmasystems.com>, gcc-help@gcc.gnu.org
Subject: Re: Is this a bug?
Date: Thu, 16 Jul 2009 18:22:00 -0000 [thread overview]
Message-ID: <4A5F6FCB.8050804@redhat.com> (raw)
In-Reply-To: <4A5F6F09.402@caviumnetworks.com>
David Daney wrote:
> Honggang Xu wrote:
>> Or my understand of keyword "volatile" is wrong, following code outputs
>> compiled by gcc 4.1.1: x=22 ,y=59
>>
>> main()
>> {
>> volatile int x=20,y=35;
>> x=y++ + x++;
>> y= ++y + ++x;
>> printf("x=%d y=%d\n" ,x,y);
>>
>> }
>>
>
> Your program has undefined behavior, the volatile may change the output,
> but it doesn't change the fact that its behavior is undefined.
>
> The problem is that the affect of the increment operator can take place
> either before or after the affect of the assignment. The compiler can
> order the affects any way that it desires between sequence points.
Actually, that's not quite true: as this expression exhibits undefined
behaviour, the compiler can return absolutely anything: it isn't limited
to just where it does the increment.
Andrew.
next prev parent reply other threads:[~2009-07-16 18:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <DDFD17CC94A9BD49A82147DDF7D545C50176D5AE@exchange.ZeugmaSystems.local>
2009-07-16 18:07 ` Honggang Xu
2009-07-16 18:17 ` Andrew Haley
2009-07-16 18:19 ` David Daney
2009-07-16 18:22 ` Andrew Haley [this message]
2009-07-16 18:28 ` Honggang Xu
2009-07-16 19:54 ` Bob Plantz
2009-07-17 0:31 ` Ian Lance Taylor
2009-07-17 2:48 ` Bob Plantz
2009-07-17 4:23 Bill McEnaney
-- strict thread matches above, loose matches on Subject: below --
2003-08-21 9:23 Lev Assinovsky
2003-08-14 9:47 Lev Assinovsky
2003-08-15 5:04 ` Alexandre Oliva
2003-08-12 16:27 Lev Assinovsky
2003-08-12 18:57 ` Alexandre Oliva
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=4A5F6FCB.8050804@redhat.com \
--to=aph@redhat.com \
--cc=ddaney@caviumnetworks.com \
--cc=gcc-help@gcc.gnu.org \
--cc=hxu@zeugmasystems.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).