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
?

- 68,093
- 33
- 169
- 336

- 30,618
- 31
- 128
- 208
-
Although I try to use `std::size_t` in interfaces I have to admit that in source files where I use `size_t` a lot I do tend use `using std::size_t;`. – CB Bailey Feb 05 '12 at 12:54
-
3@iammilind: Why the change in meaning to the question title? – CB Bailey Feb 05 '12 at 13:49
-
@CharlesBailey, the question is interesting, so I changed the title to more generic text. The other way is also ok. It will be helpful while searching from google :). To Paul, just out of curiosity, I asked. – iammilind Feb 06 '12 at 02:52
1 Answers
If you use e.g. <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++.
If you use e.g. <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).

- 378,754
- 76
- 643
- 1,055
-
Why standard has left it unspecified ? What can be the possible reason for this ? – Destructor May 15 '16 at 19:33
-