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

HM <hamotahari at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hamotahari at gmail dot com

--- Comment #2 from HM <hamotahari at gmail dot com> 2011-01-22 15:51:21 UTC ---
(In reply to comment #1)
> (In reply to comment #0)
> >     x = 20 + x++;
> 
> This is undefined behaviour because there is no sequence point between the
> increment and the assignment.
> 
> Compiling with -Wall warns you about it

I know the word "the behavior is undefined", and then this can not be a bug.
But I wrote this code in Java as the below:

public class TestXPP {
    /**
     * @param args
     */
    public static void main(String[] args) {
        int x = 10;
        x = 20 + x++;        
        System.out.println("X is: " + x);

        x = 10;
        int y = 20 + x++;        
        System.out.println("Y is: " + y);        
    }
}

And the output, both are 30:
X is: 30
Y is: 30

It seems interesting for me. It means Java doesn't assume it as an undefined
behavior point or at least Java's compiler does in a unique way and doesn't
care about being X or Y.
Can anyone explain it?

Reply via email to