This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

âx--â would self-add before opration "--" ï


Hello list,

Yestoday I encounter this problem during a test:

1    int x = 11;
2    std::cout<< x <<  x-- << ++x;

I think it should be :
11 11 11

----
I wrote the fellowing code :

#include <iostream>

int main() {
    int x = 11;
    std::cout<< x <<  x-- << ++x << std::endl;
}

compile the code above with g++ 4.5.0, after run, it gives:
11 12 11

----
#include <stdio.h>

int main() {
   int x = 11;
   printf("%d %d %d\n", x, x--, ++x);
}

the c code compiled with gcc gives the same result.

----
But when I use clang and clang++ to compile the codes above, I get:
11 11 11. 

I am not familar with both c++ and compiler implementation, donot konw 
why the results are differnt for gcc and clang. Anyone could help and 
explain this difference for me?


Thanks,

Ryan Ren


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]