3 ms·
The one thing missing from this list: Compiler optimizations can have undesirable effects. A trivial example I ran into in an older job: I was compiling a prog
by BeetleB 4y ago
The one thing missing from this list: Compiler optimizations can have undesirable effects.
A trivial example I ran into in an older job: I was compiling a program that relied on libm.so (the standard math library you get when including math.h). Now I wanted the code to use my own custom libm.so - not the one that was installed in /usr/lib or wherever, so I ensured it was dynamically compiled.
My code had some calls like:
int x = sin(3.2);
During compilation, it computed sin(3.2) using the system libm. Notably, it would not use the sine function in my custom libm.so (and indeed, I needed it to!)
And IIRC, even -O0 was not enough to prevent this from happening. I had to go through the man page to figure out which compiler flags would prevent it.
(I don't recall if this was gcc or icc).
- kccqzy 4y agoC doesn't have namespaces so the compiler is certainly within its right to deduce that the sin() function is the one from the standard library. Actually even in C++ after the compiler performs the unqualified name lookup if the result of the lookup is the standard sin() function it will make use of its internal knowledge about the function to do optimization. Remember that the C or C++ standard doesn't deal with compilers and linkers; the standard deals with the "implementation" as a whole.