When I use functions inherited from C, like the ones in <cmath>
or <cstdlib>
, should I qualify them as being part of the standard namespace std::log
, or should I remain in the C-scope and use them as global functions? What about size_t
?
<math.h>
No, you shouldn't.
It is unspecified whether they are available in the namespace std
on any particular implementation:
[C++11: D.5/2]:
Every C header, each of which has a name of the formname.h
, behaves as if each name placed in the standard library namespace by the correspondingcname
header is placed within the global namespace scope. It is unspecified whether these names are first declared or defined within namespace scope (3.3.6) of the namespacestd
and are then injected into the global namespace scope by explicit using-declarations (7.3.3).
However, you should not be using this header:
[C++11: C.3.1/1]:
For compatibility with the Standard C library, the C++ standard library provides the 18 C headers (D.5), but their use is deprecated in C++.
<cmath>
Yes, you should.
It is unspecified whether they are available in the global namespace on any particular implementation:
[C++11: 17.6.1.2/4]:
Except as noted in Clauses 18 through 30 and Annex D, the contents of each headercname
shall be the same as that of the corresponding headername.h
, as specified in the C standard library (1.2) or the C Unicode TR, as appropriate, as if by inclusion. In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are within namespace scope (3.3.6) of the namespacestd
. It is unspecified whether these names are first declared within the global namespace scope and are then injected into namespacestd
by explicit using-declarations (7.3.3).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With