SuperDicq on Nostr: Iron Bug pistolero Dire Sock :verified: "compiling your code to binary" makes it ...
Iron Bug (npub19sn…2m78) pistolero (npub1ch8…sw60) Dire Sock :verified: (npub17jq…v996) "compiling your code to binary" makes it sounds very simple.
There's often a hundred different ways you can convert C code to Assembly with exactly the same result. However, we tend to want the most optimized solution.
The hardest part of building compilers is to find the most optimized solution. So it is very understandable for compilers to simply just remove parts of the code that it deems to be unneeded considering the specifications of the language you're trying to write a compiler for.
In the case of Clang in this example, they are technically correct that skipping the if statement is valid because according to C integer overflow is considered "undefined behavior", which means anything goes, including ignoring it.
But is it really the correct choice that Clang made here from a user point of view? I don't think so, because they are doing things that the user might not expect. It's probably better if the compiler shows a warning and executes it anyway or something like that.
There's often a hundred different ways you can convert C code to Assembly with exactly the same result. However, we tend to want the most optimized solution.
The hardest part of building compilers is to find the most optimized solution. So it is very understandable for compilers to simply just remove parts of the code that it deems to be unneeded considering the specifications of the language you're trying to write a compiler for.
In the case of Clang in this example, they are technically correct that skipping the if statement is valid because according to C integer overflow is considered "undefined behavior", which means anything goes, including ignoring it.
But is it really the correct choice that Clang made here from a user point of view? I don't think so, because they are doing things that the user might not expect. It's probably better if the compiler shows a warning and executes it anyway or something like that.