Hello folks!
Is it right, that it's not a very good idea to use STL datatypes
(std::string, std::list, ...) for library interfaces? Because someone
might try to use that library with a different STL implementation and is
going to run into trouble? Is there any workaround for this? Will I have
to write own datatypes or even fall back to primitive datatypes like
char* for strings?
Thanks in advance,
Daniel 13 3704
Daniel Kay wrote: Is it right, that it's not a very good idea to use STL datatypes (std::string, std::list, ...) for library interfaces? Because someone might try to use that library with a different STL implementation and is going to run into trouble? Is there any workaround for this? Will I have to write own datatypes or even fall back to primitive datatypes like char* for strings?
It may not be a good idea to use those objects for _binary_ interfaces.
You should be fine using them for template interfaces. It should be
totally fine to use them for binary interfaces within the same version
of the compiler+library combo as you use to build the library.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Victor Bazarov wrote: Is it right, that it's not a very good idea to use STL datatypes (std::string, std::list, ...) for library interfaces? Because someone might try to use that library with a different STL implementation and is going to run into trouble? Is there any workaround for this? Will I have to write own datatypes or even fall back to primitive datatypes like char* for strings?
It may not be a good idea to use those objects for _binary_ interfaces. You should be fine using them for template interfaces. It should be totally fine to use them for binary interfaces within the same version of the compiler+library combo as you use to build the library.
If I write my own string implementation I will end up getting in trouble
with different name mangling when different compilers are being used.
Right? Slowly I think there is no clean and safe way to create library
interfaces using c++ language features when it comes to compiler
independance. What a pitty... :(
Cya,
Daniel
On Wed, 10 May 2006 21:39:33 +0200, Daniel Kay <da********@arcor.de>
wrote: If I write my own string implementation I will end up getting in trouble with different name mangling when different compilers are being used. Right? Slowly I think there is no clean and safe way to create library interfaces using c++ language features when it comes to compiler independance. What a pitty... :(
If you want maximum portability then you must write a C interface for
your C++ library.
Best wishes,
Roland Pibinger
Roland Pibinger wrote: On Wed, 10 May 2006 21:39:33 +0200, Daniel Kay <da********@arcor.de> wrote: If I write my own string implementation I will end up getting in trouble with different name mangling when different compilers are being used. Right? Slowly I think there is no clean and safe way to create library interfaces using c++ language features when it comes to compiler independance. What a pitty... :(
If you want maximum portability then you must write a C interface for your C++ library.
I believe that maximum portability can only be reached if the library is
shipped in the source code form. No need for C interface then. After
all, didn't we switch to using C++ to avoid having to go into C?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Wed, 10 May 2006 15:50:08 -0400, "Victor Bazarov"
<v.********@comAcast.net> wrote: Roland Pibinger wrote: If you want maximum portability then you must write a C interface for your C++ library. I believe that maximum portability can only be reached if the library is shipped in the source code form. No need for C interface then.
A C library can be used in most popular languages: Scripting
languages, ... even Java. A huge advantage.
After all, didn't we switch to using C++ to avoid having to go into C?
You may write your library in C++ as long as you provide a C interface
:-)
Best regards,
Roland Pibinger
Well,
¿is not C++ a Standard? ¿is not STL a Standard Template Library?
I dont understand, if i'd want a API based on C++ and export C++ Class
¿why could not i use C++ STL?
The library that i 'd want to export also have many versions, and
probably more often releases than C++ STL.
carlosrf82 wrote: Well, ¿is not C++ a Standard? ¿is not STL a Standard Template Library? I dont understand, if i'd want a API based on C++ and export C++ Class ¿why could not i use C++ STL? The library that i 'd want to export also have many versions, and probably more often releases than C++ STL.
STL only defines the interface and behaviour of the templates. But every
STL Library will implement this a different way. sizeof(std::string)
could be 12 bytes for the STL shipped with the gcc and 16 bytes for a
different implementation.
Cya,
Daniel
"carlosrf82" <ca********@gmail.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com... ¿is not C++ a Standard?
It is -- but the standard specifies the language and source code.
Not the binary representation of a compiled library.
¿is not STL a Standard Template Library? I dont understand, if i'd want a API based on C++ and export C++ Class ¿why could not i use C++ STL?
You can. But you may face problems because different
C++ platform may implement incompatible binary interfaces.
This is a platform specific issue: most operating systems
have a well-defined C binding interace -- which all compilers
and languages can adhere to.
However, only few platforms define a standard binary interface
for C++-specific features (e.g. exceptions), and for standard
library classes.
This just goes beyond the scope of the C++ language standard.
Ivan
-- http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com
Ivan Vecerina wrote: "carlosrf82" <ca********@gmail.com> wrote in message ¿is not STL a Standard Template Library? I dont understand, if i'd want a API based on C++ and export C++ Class ¿why could not i use C++ STL?
You can. But you may face problems because different C++ platform may implement incompatible binary interfaces. This is a platform specific issue: most operating systems have a well-defined C binding interace -- which all compilers and languages can adhere to.
It's not just that - there are also problems with heap management,
particularly if using a reference-counted implementation of
std::string.
I have a portable_string class (actually portable_basic_string
template) that actually is a bit like boost_array, has an implicit
constructor from a string and a non-implicit conversion back (you have
to call asString() to get a std::string back) and is reference-counted
for large strings. But because the destruction is done via a virtual
method of a deleter_base, it is safe. Originally this class was
intended to be very light so all you would do was create it, pass it
and then convert back to string locally. However in the end I
implemented most of the const methods on it. You cannot modify one
though other assigning it.
Now I said that my class uses something similar to boost_array. So you
will ask, why not just use boost_array? Because you might end up with
the same portability issues. First of all, not everybody has boost ,and
secondly there may possibly be different versions of boost_array
(someone uses a legacy version?).
Now, is all this a design flaw in C++? Should there be a C++ runtime
library?
Ok!!. Thanks, i´ve got it!!
I now understand why Trolltech make QTL and do not use STL.
"Earl Purple" <ea********@gmail.com> wrote in message
news:11**********************@q12g2000cwa.googlegr oups.com... Ivan Vecerina wrote:
"carlosrf82" <ca********@gmail.com> wrote in message > ¿is not STL a Standard Template Library? > I dont understand, if i'd want a API based on C++ and > export C++ Class ¿why could not i use C++ STL? You can. But you may face problems because different C++ platform may implement incompatible binary interfaces. This is a platform specific issue: most operating systems have a well-defined C binding interace -- which all compilers and languages can adhere to.
It's not just that - there are also problems with heap management, particularly if using a reference-counted implementation of std::string.
The same happens with malloc/free if those two functions are
not provided directly by the OS. On some platforms, a C library
can face compatibility issues if it is used by a C application
that uses a specialized implementation of malloc/free.
I have a portable_string class (actually portable_basic_string
[...] But because the destruction is done via a virtual
method of a deleter_base, it is safe.
Sure, this is a classic trick, used by COM, and various C libraries
as well. This is in no way specific to C++ or its standard library.
Now, is all this a design flaw in C++? Should there be a C++ runtime library?
Yes there should. But this is up to the platform/implementer.
Ivan
-- http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
On 11 May 2006 05:35:15 -0700, I waved a wand and this message
magically appeared from carlosrf82: Ok!!. Thanks, i´ve got it!! I now understand why Trolltech make QTL and do not use STL.
It's because they abuse the langauge - they even have a preprocessor
for their 'extensions'.
I use gtkmm as it's very close to the STL, and indeed uses STL.
-- http://www.munted.org.uk
Take a nap, it saves lives.
Daniel Kay wrote: Hello folks!
Is it right, that it's not a very good idea to use STL datatypes (std::string, std::list, ...) for library interfaces? Because someone might try to use that library with a different STL implementation and is going to run into trouble?
If they have a different implementation, your new's won't match their
delete's.
If name mangling differs, your function names won't match their
headers.
So, avoiding STL isn't sufficient. You can't use any feature that the
different
sides implement differently.
HTH,
Michiel Salters This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: rollasoc |
last post by:
In C#
I have the following in a file in a DLL on its own. Which is registered
from Com Interop
public interface IOpenCloseSomething
{
bool Open();
|
by: Jessard |
last post by:
Help!
Hi, I'm having a bit (well a lot - it's getting annoying) of trouble using a
C# class library within a VBScript on a computer other than the development
machine. All the class is needed...
|
by: Joakim Persson |
last post by:
Hello all. I am involved in a project where we have a desire to
improve our software testing tools, and I'm in charge of looking for
solutions regarding the logging of our software (originating...
|
by: Abhishek Srivastava |
last post by:
Hello All,
I want my clients to use my remoted object by means of interfaces. These
interfaces also ensure clean seperation between client and server.
The approach I know to instantiate a CAO...
|
by: Bonj |
last post by:
I downloaded the gzlib library from zlib in order to do compression.
(http://www.gzip.org/zlib)
The prototype of the compression function seems to be
int compress (Bytef *dest, uLongf *destLen,...
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen....
|
by: fakeprogress |
last post by:
For a homework assignment in my Data Structures/C++ class, I have to
create the interface and implementation for a class called Book, create
objects within the class, and process transactions that...
|
by: =?Utf-8?B?UmFodnlu?= |
last post by:
Hi All;
I am writing a COM interface that will need to be called from VBScript
(Legacy App). I need to return a recordset to the calling app. I am using
ADODB to populate the recordset and...
|
by: JosAH |
last post by:
Greetings,
the last two article parts described the design and implementation of the
text Processor which spoonfeeds paragraphs of text to the LibraryBuilder.
The latter object organizes, cleans...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |