Thread: STL includes in distributed SDK headers?

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    4

    STL includes in distributed SDK headers?

    Hello,

    I'm writing my own SDK for a 3D engine. Obviously it contains many classes and structs. One of the class I'm publishing to the users needs to use an STL member, the std::vector for instance.

    My question is, how dangerous is it to include STL objects in a header file that I distribute in my SDK? Obviously, to be able to have this vector member in my class, I include <vector> in that header file, hence my question.

    I don't know what is the real danger, but I feel like this might cause some trouble... its just a feeling I have. This fear comes from the fact that I don't know if it is still common for developers to update or change the version of STL they are using. I can't find any detailed discussion on this very specific subject.

    Can anyone confirm if this is bad practice, and if there is a work-around or a correct way to do this?

    Thank you!

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Using STL in any user-visible portion of an SDK is usually a no-no, because different implementations of STL are not binary compatible. If your public APIs and classes include STL objects, you force the user to use the exact same version of STL (and quite possibly the same compiler) that you compiled the SDK with.

    That doesn't mean you can't use STL, but it does mean that all references to STL must be completely hidden inside .cpp files -- no user-visible data types may include any STL objects. if some user-visible class needs to have an STL member, this member needs to be dynamically allocated and abstracted into a void *, or the whole class needs to be abstracted using Pimpl.

    If you absolutely require that STL be part of the API, then you'll need to distribute the STL along with your SDK, so the user can use the exact same implementation the SDK uses. STLPort would be one possibility. I recommend staying away from it in your public APIs, though.
    Last edited by brewbuck; 02-12-2010 at 02:02 PM.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    4
    Ok thank you, that is what I feared.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDK headers
    By techi_talk in forum C++ Programming
    Replies: 1
    Last Post: 11-26-2005, 09:35 AM
  2. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM