public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Tree generation bug or a feature?
@ 2000-05-24  5:49 Yuri Pudgorodsky
  2000-05-24  6:05 ` Dima Volodin
  2000-05-24  6:05 ` Nathan Sidwell
  0 siblings, 2 replies; 3+ messages in thread
From: Yuri Pudgorodsky @ 2000-05-24  5:49 UTC (permalink / raw)
  To: gcc

Hi!


With the following two statements, I supposed to get identical result:

x = 2;  y = ++x * ++x;
x = 2;  y = (x+=1) * (x+=1);

However, under gcc  ++x  variant  gives me 16 instead if 12,
as well as x++ * x++ incorrectly (I suppose) gives 4.


Digital C compiler from DU 4.0 show correct values:

++x * ++x = 12
(x+=1) * (x+=1) = 12

as well as gdb builtin C expression parser.


Sounds like a tree generation bug, isn't it?


Regards,
Yuri Pudgorodsky


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Tree generation bug or a feature?
  2000-05-24  5:49 Tree generation bug or a feature? Yuri Pudgorodsky
  2000-05-24  6:05 ` Dima Volodin
@ 2000-05-24  6:05 ` Nathan Sidwell
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Sidwell @ 2000-05-24  6:05 UTC (permalink / raw)
  To: Yuri Pudgorodsky; +Cc: gcc

Yuri Pudgorodsky wrote:
> With the following two statements, I supposed to get identical result:
> 
> x = 2;  y = ++x * ++x;
> x = 2;  y = (x+=1) * (x+=1);
> 
> Sounds like a tree generation bug, isn't it?
No. you've invoked undefined effects see
http://www.eskimo.com/~scs/C-faq/s3.html

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Tree generation bug or a feature?
  2000-05-24  5:49 Tree generation bug or a feature? Yuri Pudgorodsky
@ 2000-05-24  6:05 ` Dima Volodin
  2000-05-24  6:05 ` Nathan Sidwell
  1 sibling, 0 replies; 3+ messages in thread
From: Dima Volodin @ 2000-05-24  6:05 UTC (permalink / raw)
  To: Yuri Pudgorodsky; +Cc: gcc

On Wed, 24 May 2000 16:48:47 +0400, you wrote:

>Hi!
>
>
>With the following two statements, I supposed to get identical result:
>
>x = 2;  y = ++x * ++x;
>x = 2;  y = (x+=1) * (x+=1);
>
>However, under gcc  ++x  variant  gives me 16 instead if 12,
>as well as x++ * x++ incorrectly (I suppose) gives 4.
>
>
>Digital C compiler from DU 4.0 show correct values:
>
>++x * ++x = 12
>(x+=1) * (x+=1) = 12
>
>as well as gdb builtin C expression parser.
>
>
>Sounds like a tree generation bug, isn't it?

In these code snippets, you are trying to modify x's value more than
once, which makes these snippets undefined as per section 6.3 of the
ANSI/ISO C Standard. That is you cannot expect any particular result at
all.

>Yuri Pudgorodsky

Dima

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-05-24  6:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-24  5:49 Tree generation bug or a feature? Yuri Pudgorodsky
2000-05-24  6:05 ` Dima Volodin
2000-05-24  6:05 ` Nathan Sidwell

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).