I have two functions in my shared library which are declared as
follows:
void setName(const std::string& str);
std::vector<std ::string> getInfo();
Since the code is compiled and in shared library. Every thing is great
if the customer of my shared library is using the same compiler
version (and same STL version). I am wondering if the customer changes
their compiler version (or STL version) which may have same interface
for all the standard containers, but different implementations and
sizes; will it still work with my shared library?
Here's an example:
The first function I mentioned above takes a const std::string as an
argument. The compiler I used to build my library (say for example)
defines the std::string something like this (I've omitted the
interface and namespace for simplicity)
template<typena me T>
class basic_string
{
T* buffer;
size_t size;
public:
// public interface for std::string goes here
};
typedef basic_string<ch ar> string; // string I used in my first
function
Now say the customer is using an updated version of the same compiler
or some other compiler which defines the std::string by adding an
additional private variable 'count' for reference counting as follows:
template<typena me T>
class basic_string
{
T* buffer;
size_t size;
unsigned long* count;
public:
// public interface for std::string goes here
};
Problem:
As you can see the customer passes the new string to my function which
has different size. The function I wrote originally expected a
std::string of a smaller size. Will this break my shared library???
Same thing is also can be said about the second function which returns
a vector of strings, but container returned might be different as what
compiler expects it to be if they are of different sizes.
What I am getting at is that is it a bad idea to use standard
containers in the interface for shared libararies? Since the standard
containers are Templated and not compiled when used by the user of a
shared library.
I hope you understand the problem. Any response will be greatly
appreciated.
Thank you,
Adnan 1 4422
AH wrote: I have two functions in my shared library which are declared as follows:
void setName(const std::string& str); std::vector<std ::string> getInfo();
Since the code is compiled and in shared library. Every thing is great if the customer of my shared library is using the same compiler version (and same STL version). I am wondering if the customer changes their compiler version (or STL version) which may have same interface for all the standard containers, but different implementations and sizes; will it still work with my shared library?
Here's an example: The first function I mentioned above takes a const std::string as an argument. The compiler I used to build my library (say for example) defines the std::string something like this (I've omitted the interface and namespace for simplicity)
template<typena me T> class basic_string { T* buffer; size_t size; public: // public interface for std::string goes here };
typedef basic_string<ch ar> string; // string I used in my first function
Now say the customer is using an updated version of the same compiler or some other compiler which defines the std::string by adding an additional private variable 'count' for reference counting as follows:
template<typena me T> class basic_string { T* buffer; size_t size; unsigned long* count; public: // public interface for std::string goes here };
Problem:
As you can see the customer passes the new string to my function which has different size. The function I wrote originally expected a std::string of a smaller size. Will this break my shared library???
Same thing is also can be said about the second function which returns a vector of strings, but container returned might be different as what compiler expects it to be if they are of different sizes.
What I am getting at is that is it a bad idea to use standard containers in the interface for shared libararies? Since the standard containers are Templated and not compiled when used by the user of a shared library.
I hope you understand the problem. Any response will be greatly appreciated.
Thank you,
Adnan
You will have the same problem with any user defined types. If you are
passing user defined types from/to the client (user of the shared
library), the client needs to know the size of the user defined type. So
if you change the implementation of the user defined type in the shared
library, it will cause problems in the client.
To get over this problem, instead of using user defined types for
communication between library and client , use interfaces . Also to
create objects in the shared library use class factory pattern.
Hope this helps. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Phil |
last post by:
I realize this is the php group, but I have a question that recurses
back to my php install.
My objective is a pure 64 bit shared object installation of php 5.0 on
UltraSparc Solaris 9 compiled with the Sun Compiler version 8.
My problem is that EVERYTHING builds great EXCEPT that the 6b
distribution of JPEG will NOT build a shared object, thus gd cannot
include support for JPEG, thus php loses that functionality.
|
by: Rickard Lind |
last post by:
Is there any way to build the python executable statically and
still be able to load modules built as shared libraries?
I'm trying to run python scripts on a stripped down FreeBSD (4.9)
machine which has no shared system libraries so I want to link it
statically against libc et al, but it would be nice to still be
able to load modules which were built as shared libraries. In
particular I have a library for which I've generated a wrapper...
|
by: SpaceCowboy |
last post by:
I recently got into a discussion with a co-worker about using enums across a
dll interface. He wanted to use chars instead, argueing that depending on
compiler settings the size of an enum could change and lead to memory
corruption. I didn't see how this was possible. He claims that if a dll
built for a program is built with different compiler settings than the
launcher program, the enum size could change.
The only way I could figure...
|
by: Alan Krueger |
last post by:
Greetings,
I've been able to cache Transformer objects in a Tomcat-based servlet
application to avoid unnecessary Transformer rebuilding, except for
certain ones on certain machines. I'm running Tomcat 4.1.27 under
Eclipse 2.1.0 using the Sysdeo Tomcat plugin using j2re1.4.1_02 under
Windows 2000 SP4.
I've digested this down to a small (albeit convoluted) sample that
exhibits the behavior reliably on my development workstation.
|
by: Rob Ratcliff |
last post by:
I'm compiling the latest version of a CORBA ORB called MICO on a Cray
X1. It makes heavy use of templates and namespaces.
Up until the link step, the C++ source code compiled flawlessly. But,
when it tried to link, I got the attached warnings and then an error.
Any ideas why the linker wouldn't see the objects in the library? They
look like pretty long names,
so maybe there is some type of symbol length or mangling issue going
on? The...
| |
by: Leslaw Bieniasz |
last post by:
Cracow, 15.09.2004
Hi,
I am writing a big C++ project using BCB 4.0. The project
consists of several dlls and exes. Each of the dll
is composed of several units (that is cpp files with corresponding h files)
containing:
1) ordinary C++ classes or functions,
2) class templates or function templates.
I want the code for templates to reside within the dlls,
|
by: Christian Christmann |
last post by:
Hi,
I want to implement an graph using templates.
In my header file I define the templates node and edge:
template <class NODE> class GNode
{
NODE *info;
public:
GraphNode();
|
by: ZR |
last post by:
I am writing two applications which needs to (among other things)
communicate through network, so one of them is a client and the other one is
a server. I have used asynchronous socket examples found at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconblockingclientsocketexample.asp
as templates (they have to be asynchronous, because application must not
freeze if connection fails). I have converted the...
|
by: David T. Ashley |
last post by:
I've occasionally had trouble compiling and linking programs that use shared
libraries. That never made a lot of sense to me, because I thought the
operating system went hunting for the symbols and libraries at runtime (and
not before).
Questions:
a)How do the development tools know that a given symbol (a function entry
point, for example) is located in a shared library and won't be linked in
statically?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |