For example, let's look at the sad story of C runtime library in C++. When
namespaces were invented, it was decided that in C++, contents of the C
runtime library will be in the std
namespace. Seems like a
better design, but change to that better design creates a lot of
problems.
- Compilers did not switch in an instant. Some have the C runtime in the
std
namespace now, and some don't. As the result, you need macro logic in every module which uses the C library. Or you need your own header file for each C library header, and must make sure that you always include only your replacement headers, not the standard ones. - It is convenient to add
using namespace std;
to the top of a source file (not header!) and then use unqualified names everywhere. Unfortunately, you can get an error about an ambiguity between global name and thestd::
name. This happens, for example, with msvc/stlport combination and is a compiler bug. - You won't expect that error from better compilers, but standard library
which ships with one of them declares global functions with
extern "C"
andstd::
without. Again, the compiler reports ambiguity. This time the compiler is correct, and the problem is with the library.
Today, I certainly know more about those quirks that I would like. Was moving the
C library to std::
a good idea? Decide for yourself.
No comments:
Post a Comment