Sat 15 Dec 2007

Hooray, C and C++

On my current Solaris box, /usr/include/sys/stream.h declares queue.

The C++ Standard Library declares queue as one of its standard containers.

Guess what happens when you try to compile some software that includes both headers? Yaay, errors! “/usr/include/sys/stream.h:67: error: redeclaration of `std::queue<_Tp, _Sequence>' as a non-template”.

Even worse, the definition of ifnet in /usr/include/net/if.h refers to map, which gets confused with std::map by g++. You get a beautiful error message: “/usr/include/net/if.h:87: error: template argument required for `struct map'”.

I'm going to have to go crawling through someone else's source, chopping out their using namespace std and using std::queue lines, fully-qualifying symbols.

Just another reason to hate C++. Perhaps I shouldn't be hating on C and C++, and instead hating on programmers who don't take enough care over portability. Or maybe I should be hating on the languages for making it too easy to shoot other people in the foot…

Posted at 2007-12-15 00:31:36 by RichardLink to Hooray, C and C++