STL and Metakit

I have been investigating using STL with Metakit 2.01, using Symantec C++ as the compiler. Some of the notes may be compiler specific and some may be of wider usefulness.

There are several versions of STL (Standard Template Library) and some come combined with a standard library as well. There is also an issue about how the string class is sourced, and how namespaces are handled. I have been using one STL SGI 3.20 which has a string class and no standard library. It can be used without namespaces. To use this I have to define the following macros to build the library.

q4_STD q4_NO_NS

For Symantec C++ it is necessary also to this in header.h and in user code to ensure that string objects are properly terminated:

 #define __STL_DEFAULT_CONSTRUCTOR_BUG

This successully converts Metakit to use the string class in the STL.

However the header file mk4str.h does not check for q4_NO_NS so the user code fails to compile until the equivalent test is moved over from header.h

I had one further problem with the programs crashing which I have traced to field.cpp in the library. The code of the function

  c4_String c4_Field::Description(bool anonymous_) const

contains the line

  c4_String s = anonymous_ ? "?" : (const char*) Name();

which fails when Name() returns an object derived from an STL string, at least for my compiler (Symantec C++). I replaced this with

  c4_String s;
  if (anonymous_) s = "?"; else /* (const char*) */ s = Name();

which seems to work for both q4_STD and q4_UNIV

This part seems to be specific to the compiler and concerned with conversions as the equivalent of the following works:

  c4_String s = anonymous_ ? c4_String("?") : Name();

I hope this helps. I have not checked this on more recent Metakit.


Since I wrote the above I have been able to use the same techniques with e4Graph.

-- John Fletcher