| ▲ | mbrock 2 hours ago | |||||||||||||||||||||||||
This is a description of an imaginary compiler, evoked by the ANSI/ISO standards documents, which has never existed and will never exist. To understand what the program will do, you just have to understand the compiler behavior on your target platforms. A helpful intuition pump is: imagine the ANSI/ISO specifications simply do not exist; now what? Well, you just continue your engineering practice, the way you would for any of the myriad languages that never even had a post hoc standards document. | ||||||||||||||||||||||||||
| ▲ | JonChesterfield 3 minutes ago | parent | next [-] | |||||||||||||||||||||||||
Not imaginary. Eliding checks on nullptr and integer overflow were both implemented, shipped, miscompiled the linux kernel and grew flags to disable them. I expect there are more if one goes looking. | ||||||||||||||||||||||||||
| ▲ | simonask an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||
> just That word is carrying a lot of weight here. Compilers are unbelievably complex these days, and it's impossible for any one human to fully understand the entire compilation process, including the effects of any arbitrary combination of compiler flags. Any assumptions you have about what the compiler does in the face of UB will collapse on the next patch release of that compiler, or the moment somebody changes the compiler flags, or the moment somebody tries to compile the code for a slightly different OS, not to mention architecture. There is no other way to understand what C compilers do than reading the standard. | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
| ▲ | Retr0id 41 minutes ago | parent | prev [-] | |||||||||||||||||||||||||
GCC -O1 and clang -O1 will both optimize this function under the assumption that inputs that cause signed integer overflow are never passed: | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||