Hacker News new | past | comments | ask | show | jobs | submit login

I noticed that ICC 13 on Godbolt compiled it "correctly", assuming correctly means as written. I wondered if this was just because it's an older version that wasn't yet optimized, so I tried with the current ICC 17 Beta. But with all the optimization options I tried, it stuck to its guns and compiled it as written:

   0:	c7 07 03 00 00 00    	movl   $0x3,(%rdi)
   6:	c7 05 00 00 00 00 04 	movl   $0x4,0x0(%rip)
   d:	00 00 00
  10:	8b 07                	mov    (%rdi),%eax
  12:	c3                   	retq
From what I can tell testing with http://webcompiler.cloudapp.net, MSVC seems to also produce the "correct" result at all optimization settings, while GCC and Clang do so only with -O1 or lower for all versions that I tried.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: