-1

The codes in this Post-increment within a self-assignment, testing with C++.

However I get different result between VS2013 and GCC4.8.4

int cc = 42;
cc = cc++;
cout << cc << endl;

The result of VS2013 is 43, but the result of GCC is 42. It confuse me...

Which result is correct?

Community
  • 1
  • 1
zangw
  • 43,869
  • 19
  • 177
  • 214

1 Answers1

2

This is textbook undefined behavior. The compiler can do whatever the hell it wants to. By the language spec, it is allowed to halt and catch fire, should it so choose; be glad they just did something vaguely related to the nonsense you fed them.

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271