public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/44918]  New: Calculation on y = x++ + x++ depends on following statements
@ 2010-07-12  9:13 eric dot liu at uniquesoft dot com
  2010-07-12  9:20 ` [Bug c/44918] " rguenth at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: eric dot liu at uniquesoft dot com @ 2010-07-12  9:13 UTC (permalink / raw)
  To: gcc-bugs

#include <stdio.h>

void UnspecifiedSideEffectInExpression(int c)
{
        int x = 0, y = 0, z = 20, t = 30, *p, *q;

        x = c;
        y = x++ + x++;
        printf("x = %d, y = %d\n", x, y);

        //Comment out the following code to get a different result
        p = (c&2) ? &x : &t;
        printf("*p = %d\n", *p);

}

int main()
{
        UnspecifiedSideEffectInExpression(1);

        return 0;
}


-- 
           Summary: Calculation on y = x++ + x++ depends on following
                    statements
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: eric dot liu at uniquesoft dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44918


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

* [Bug c/44918] Calculation on y = x++ + x++ depends on following statements
  2010-07-12  9:13 [Bug c/44918] New: Calculation on y = x++ + x++ depends on following statements eric dot liu at uniquesoft dot com
@ 2010-07-12  9:20 ` rguenth at gcc dot gnu dot org
  2010-07-12  9:35 ` eric dot liu at uniquesoft dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-07-12  9:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2010-07-12 09:19 -------
There is no sequence point between the two modifications to x.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
   GCC host triplet|CentOS 5.3 on i386          |
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44918


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

* [Bug c/44918] Calculation on y = x++ + x++ depends on following statements
  2010-07-12  9:13 [Bug c/44918] New: Calculation on y = x++ + x++ depends on following statements eric dot liu at uniquesoft dot com
  2010-07-12  9:20 ` [Bug c/44918] " rguenth at gcc dot gnu dot org
@ 2010-07-12  9:35 ` eric dot liu at uniquesoft dot com
  2010-07-12  9:50 ` eric dot liu at uniquesoft dot com
  2010-07-12  9:54 ` steven at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: eric dot liu at uniquesoft dot com @ 2010-07-12  9:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from eric dot liu at uniquesoft dot com  2010-07-12 09:34 -------
I don't understand what is sequence point.
But as a user, I DO want gcc to produce the same result.
As for the code in the bug description, the result is:
x = 2, y = 2
*p = 30

If comment out the code indicated in the bug description, the result is
x = 3, y = 2

The result is different. Why?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44918


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

* [Bug c/44918] Calculation on y = x++ + x++ depends on following statements
  2010-07-12  9:13 [Bug c/44918] New: Calculation on y = x++ + x++ depends on following statements eric dot liu at uniquesoft dot com
  2010-07-12  9:20 ` [Bug c/44918] " rguenth at gcc dot gnu dot org
  2010-07-12  9:35 ` eric dot liu at uniquesoft dot com
@ 2010-07-12  9:50 ` eric dot liu at uniquesoft dot com
  2010-07-12  9:54 ` steven at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: eric dot liu at uniquesoft dot com @ 2010-07-12  9:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from eric dot liu at uniquesoft dot com  2010-07-12 09:49 -------
Refer to my previous comment, I need to reopen it for a correct answer.


-- 

eric dot liu at uniquesoft dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44918


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

* [Bug c/44918] Calculation on y = x++ + x++ depends on following statements
  2010-07-12  9:13 [Bug c/44918] New: Calculation on y = x++ + x++ depends on following statements eric dot liu at uniquesoft dot com
                   ` (2 preceding siblings ...)
  2010-07-12  9:50 ` eric dot liu at uniquesoft dot com
@ 2010-07-12  9:54 ` steven at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: steven at gcc dot gnu dot org @ 2010-07-12  9:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from steven at gcc dot gnu dot org  2010-07-12 09:54 -------
The correct answer is: "here is no sequence point between the two modifications
to x.".

If you don't know what a sequence point is, use Google (see first hit,
Wikipedia).
If you don't know C, don't use C.
And don't reopen bugs because you're too bloody lazy to do any searching
yourself.


-- 

steven at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44918


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

end of thread, other threads:[~2010-07-12  9:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-12  9:13 [Bug c/44918] New: Calculation on y = x++ + x++ depends on following statements eric dot liu at uniquesoft dot com
2010-07-12  9:20 ` [Bug c/44918] " rguenth at gcc dot gnu dot org
2010-07-12  9:35 ` eric dot liu at uniquesoft dot com
2010-07-12  9:50 ` eric dot liu at uniquesoft dot com
2010-07-12  9:54 ` steven at gcc dot gnu dot org

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