weird behavior with post-increment operator

It seems like the post-increment (++) operator doesn’t work the way I expected it to.

int x = 0;
int y = x++ + x;

y is assigned 0 when running in emulation mode (which is the result I expect), but y is assigned 1 in non-emulation mode.

Is it just my card? Or is this the correct behavior of the post-increment operator in Cuda? Thanks. Btw, I’m using Cuda 2.1 with a 280GTX.

Nothing to do with your card and everything to do with compilers. There is nothing in the C standard which will guarantee the result of that code. Formally, any sequence can modify a value at most once, but there are no rules governing when the write of that value occurs within evaluation of the sequence. The result is completely at the whim of the register usage philosophy of the compiler and the architecture itself.

In short, don’t write code like that and expect it to be portable or even produce the results you might expect.