Standard C library namespace

S

Szabolcs

According to the standard, should the standard C functions be in the std
namespace?

So, which one is correct:

#include <cmath>
int main() { sqrt(10.0); }

or

#include <cmath>
int main() { std::sqrt(10.0); }

?

All compilers I tried accept both variants, but I'd like to know which
is the "official" one.

Szabolcs
 
B

Bo Persson

Szabolcs wrote:
:: According to the standard, should the standard C functions be in
:: the std namespace?
::
:: So, which one is correct:
::
:: #include <cmath>
:: int main() { sqrt(10.0); }
::
:: or
::
:: #include <cmath>
:: int main() { std::sqrt(10.0); }
::
:: ?
::
:: All compilers I tried accept both variants, but I'd like to know
:: which is the "official" one.
::

Currently, the second one is what the standard requires.

However, in the draft for the next standard (C++09 ?) the first option
is also acceptable. This actually documents what most (but not all)
compilers have done all the time.


Now it is up to you: In user code option 2 is required to work, option
1 will soon be allowed to work. :)


Bo Persson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,426
Latest member
MrMet

Latest Threads

Top