I came to this conclusion when I was trying to figure out what was going on with the code below:
#include <iostream>
int main()
{
std::cout << (div) << '\n';
return 0;
}
div
above could be substituted with printf
, atoi
, difftime
, etc. Whether or not I was #include
ing the appropriate headers (ctime
, time.h
, cstdlib
, ..., ), I was getting no compiler errors and the program was printing 1
. Program was not compiling when I was prefixing the function name with std::
.
Clang
's warnings explained what was going on:
warning: address of function 'div' will always evaluate to 'true' [-Wbool-conversion]
So my questions are:
- Why do names of C library function have any meaning even when the appropriate headers are not
#include
d? - Why are they defined as pointers to functions?
- Why do they reside outside namespace
std
?