This code is correct C++:
#include <ctime>
int main()
{
std::time_t t = std::time(nullptr);
}
However, this compiles fine too (GCC 5.2):
#include <ctime>
int main()
{
time_t t = time(nullptr);
}
More generally, it seems that legacy "C" data types and functions don't require namespace qualifying.
It seems to me that this is a dangerous behaviour, as both are accepted and the possibility of name collision is still there. I thought (erroneously ?) that the standard namespace std
was there to protect me against this.
So my question is: why did the standardization committee allow such a behaviour in C++11 ? Am I wrong in my analysis ?
I understand the issues about legacy code, but I though the ".h" header files (iostream.h
, ...) were there specifically to address this point.
Edit: the linked question is not a duplicate, it asks about if one should or not use the std::
version of legacy functions. What I want to know is the rationale behind this behaviour.