This question is a follow-up question of this one.
Consider the following program:
#include <cmath>
// meaningless, only for language-lawyer purpose
void abs(void*) {}
int main(){
abs(nullptr);
}
Does this program result in undefined behavior?
The related part in the standard is [extern.names]/4:
Each function signature from the C standard library declared with external linkage is reserved to the implementation for use as a function signature with both extern "C" and extern "C++" linkage, or as a name of namespace scope in the global namespace.
I'm not sure whether overloading is permitted.
int abs(int);
is a function signature from the C Standard library declared with external linkage. The non-bold text says this signature is reserved; but then the bold part goes on to say that the signature is reserved as a name, which makes no sense – Despainhtons
for example. While not a "reserved" function that I know of, it highlights how poor some implementations can be. – Halfbreedhtons
is not a Standard C function, which is why it's not covered by that rule. – Kenakenafstd
. So your example doesn't apply. – Allbeeint main()
. All other stuff can happily live in an anonymous namespace. – Allbee