logoalt Hacker News

glitchc • today at 3:23 PM • 2 replies • view on HN

I don't think GCC is doing something special, rather that -O3 might be optimizing out the subtraction. Try with -O0, I suspect you will get the same result as clang.


Replies

8-prime • today at 3:44 PM

The GCC compiler changes the order of the operations such that the assignment happens after the print for x.

call __printf_chk@PLT mov ecx, DWORD PTR 0[rbp] mov rdx, rbp mov edi, 2 mov DWORD PTR -96[rbx], 7

mkarrmann • today at 3:57 PM

The "special" thing of note is that GCC considers it acceptable to change the semantics of this program depending on the optimization level.