Menu

STL not very portable

2002-04-08
2002-04-19
  • Jason Rohrer

    Jason Rohrer - 2002-04-08

    Your code is really great, and it seems to parse XML without a hitch.  I've used it on both Linux and BSD without any issues at all.

    However, tonight I tried porting my (otherwise portable) app to windows.  It's a relatively large app, 10k lines of portable c++ code.  Anyway, everything compiles fine in Metrowerk CodeWarrior except for tinyxml... all because of that pesky std::string.  Apparently, CW can compile std::string fine if you're building a console app, but when you try to build a win32 app (my app needs sockets and threads), the necessary precompiled header seems to conflict with <string>.

    So... I was thinking about going through tinyxml and stripping out the use of std::string... maybe using plain old c-strings instead.  However, you seem to be using std::string in a particular way, so this translation might not be easy or bug-free.

    Further, you are only using a small subset of the std::string functionality, basically just .c_str() and overloaded assignment operators.  Maybe it would be easiest to write my own implementation of std::string that provides only the functionality that you are using.  CW can compile templates fine with Win32 apps, just not <string>.

    So, do you have any tips on how I should proceed?  Can you tell me what the point of std::string is in the first place (doesn't it do some kind of safe, automatic memory management???)

    Also, just to let you know, many people avoid using STL for portability reasons (for example, the Mozilla code portability guide forbids the use of STL... but then again, it also forbids the use of templates in general, which seems too strict to me.)

    Solutions that *won't* work for me are:
    --Use another compiler (I only have CW)
    --Use another XML parser (I'm locked into tinyxml throughout my app code)
    --Forget about porting to windows (even though I don't use windows, lots of other people apparently do!)

     
    • Lee Thomason

      Lee Thomason - 2002-04-16

      Try replacing <string> with <string.h> and removing all the std:: and "using namespace" code. Sounds like you may only have support for the earlier STL implementation.

      Using of STL in general is a tough call. Some, for good reason, refuse to use STL due to portability concerns. On the other hand...some require STL because of portability concerns. TinyXml would be much less useful if you had to put up with my string class.

      lee

       
      • Lee Thomason

        Lee Thomason - 2002-04-19

        Check out the option STL proposal.

         

Log in to post a comment.