Take a look at this tiny program.
#include <iostream>
int main(){
int var = atoi("-99"); //convert string to int
var = abs(var); //takes absolute value
std::cout << var+1 <<'\n'; //outputs 100
return EXIT_SUCCESS;
}
Compiling creates the following errors messages:
$ g++ -o main main.cpp
main.cpp: In function ‘int main()’:
main.cpp:5:13: error: ‘atoi’ was not declared in this scope
main.cpp:6:16: error: ‘abs’ was not declared in this scope
main.cpp:9:10: error: ‘EXIT_SUCCESS’ was not declared in this scope
Understandable. All of these exist in the "cstdlib" header which I neglected to include.
However, compiling with:
$ g++ -std=c++0x -o main main.cpp
creates no issues.
looking at the source of the "cstdlib" header, I see the following code at the bottom:
#ifdef __GXX_EXPERIMENTAL_CXX0X__
# if defined(_GLIBCXX_INCLUDE_AS_TR1)
# error C++0x header cannot be included from TR1 header
# endif
# if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
# include <tr1_impl/cstdlib>
# else
# define _GLIBCXX_INCLUDE_AS_CXX0X
# define _GLIBCXX_BEGIN_NAMESPACE_TR1
# define _GLIBCXX_END_NAMESPACE_TR1
# define _GLIBCXX_TR1
# include <tr1_impl/cstdlib>
# undef _GLIBCXX_TR1
# undef _GLIBCXX_END_NAMESPACE_TR1
# undef _GLIBCXX_BEGIN_NAMESPACE_TR1
# undef _GLIBCXX_INCLUDE_AS_CXX0X
# endif
#endif
I'm not sure if that is relevant or not.. full header file code here
my ultimate question is, does the new standard guarantee that all of cstdlib will be brought in at a global namespace when you include iostream?
I can't find any documentation on the matter. Appears that way to me, does it appear that way to you?
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1