I am working on compiling a very old piece of legacy code with g++ 4.4.7. All I really know about this code is that it was developed on a Irix/Sun system meaning it had a MIPS architecture. One rather odd thing I found when working with this code is that it sometimes calls function like endl
and set_new_handler
without the std::
prefix. Obviously this results in a compilation error. Since I am working under the assumption that this piece of code compiled on some machine at some time, I am a bit wary about blindly adding the std::
prefix to make it compile since It may change the behavior.
So, is there some old non-ISO compiler that allowed this piece of code to compile? Or is there some sort of flag that I can pass to gcc that would allow this piece of code to work?
The std
namespace wasn't introduced into C++ until the first ISO/IEC standard in 1998 (often referred to as C++98). Prior to that time all of the standard library functions and objects were part of the global namespace.
Herb Sutter wrote a piece called Migrating to Namespaces in 2000 detailing his advice on making the transition.
I am not aware of any compiler flags that would fold the std
namespace into the global one, and it would be a bad idea anyway - std
is much larger today than when it was first introduced, and name collisions would be almost certain. See Why is “using namespace std” considered bad practice?
It is unlikely that you would have a collision with names that were part of the standard library prior to 1998, so it should be safe to pull those names individually into the global namespace. If you are using precompiled headers you can put the using
directives in there after including the standard headers that define the symbols and fix the entire project silently. Just add a line for each compiler error you run across.
using std::endl;
using std::set_new_handler;
I would only advise this if your goal is to get the code up-and-running in as little time and effort as possible. The better long-term solution is still to put std::
in front of all the names from the library.