calling functions with STL parameters from a shared library

I know that it's not possible to safely export a function C++ parameters (eg STL strings), because C++ does not specify a standard ABI. (I've read that as an answer to How to call a function from a shared library? )

People tend to believe that if both your library and your program have been built with the same compiler then this isn't an issue, but unfortunately, for some VC++ compilers, this is not entirely true.

Herb Sutter and Alexandrescu in "C++ Coding Standards" propose to rely on portable types (eg built-in types) instead of a function that takes a string.

ie instead of using std::string in a module interface

 std::string Translate( const std::string & );

use a

void Translate( const char *src, char* dest, size_t destSize );

Although they agree this is fairly complex for both the caller and the callee, they don't propose a nicer alternative.

How can one nicely pass a more complex object, such as a std::map using low-level types? (not to mention something as complex as map >)

How do you tackle such cases when exporting functions ?

10
задан Community 23 May 2017 в 10:29
поделиться