Hi,
I am facing one problem related to global variables in .so file. When
ever I access the variable the application is crashing
I have a class called services.
class services
{
services(){ }
void Add() { }
void Delete(){ }
};
In another file I declared my global variable like this
services gserviceObj;
Now I used this global variable 'gserviceObj' to access the member
function 'Add()',
gserviceObj.Add (); I am calling this Add() method of gserviceObj in
another file where the gserviceObj is declared as extern.
The application is crashing at gserviceObj.Add ();. The constructor of
services is also not called till that point.
These all the files are in one .so. If I move the 'services
gserviceObj;' declaration to main and change the all the other
declarations in library(.so) to extern my application is working fine.
Is there is any way to initialize the global variables in .so files
other than declaring it in main.
Can anybody help me in this?
Thanks,
Vinu 2 2821
On 5 Jan 2006 20:04:22 -0800, "Vinu" <vi*********@ya hoo.com> wrote in
comp.lang.c++: Hi, I am facing one problem related to global variables in .so file. When ever I access the variable the application is crashing
The C++ language does not know anything at all about .so files. This
is an implementation detail of your compiler and operating system
combination.
You need to ask in a group that specifically supports your platform
and compiler. Perhaps news:comp.os.li nux.development .apps, or
news:comp.unix. programmer.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Vinu wrote: Hi, I am facing one problem related to global variables in .so file. When ever I access the variable the application is crashing
I have a class called services. class services { services(){ } void Add() { } void Delete(){ } };
In another file I declared my global variable like this services gserviceObj;
Now I used this global variable 'gserviceObj' to access the member function 'Add()',
gserviceObj.Add (); I am calling this Add() method of gserviceObj in another file where the gserviceObj is declared as extern.
The application is crashing at gserviceObj.Add ();. The constructor of services is also not called till that point.
These all the files are in one .so. If I move the 'services gserviceObj;' declaration to main and change the all the other declarations in library(.so) to extern my application is working fine.
Is there is any way to initialize the global variables in .so files other than declaring it in main. Can anybody help me in this?
Your problem is probably related to the order of global variable
initialization.
You can fix this by creating your object within a static function as a
static local variable.
Example:
gserviceObj
class services
{
services(){ }
void Add() { }
void Delete(){ }
static services& Get_gserviceObj ();
};
//Cpp file
services& services::Get_g serviceObj()
{
static services * gserviceObj = new services;
return *gserviceOb;
}
You call the above via the following:
services::Get_g serviceObj().Ad d();
This will garantee that when you try to call this object, that it will
be initialized. This is garanteed to work IAW C++ standards. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: R. Rajesh Jeba Anbiah |
last post by:
I'm supposed to do a big portal with multi-language support and I'm
decided to do my own instead of going for gettext. I have sort out few
implementations; most of them uses global variables. I'm bit confused,
how it will affect the performance. Right now, I use global variables
in config file. Most of the experts in this group are ranting against
global variable usage. I would like to know how would you handle such
config settings (DB is...
|
by: David T. Ashley |
last post by:
Hi,
In my project, I typically declare and define variables in the .H
file, i.e.
DECMOD_MAIN UINT8 can_message_201_status_global
#ifdef MODULE_MAIN
= HAS_NEVER_BEEN_RECEIVED
#endif
;
|
by: Kleenex |
last post by:
Reason: I am working on an embedded project which has very limited
memory (under 512 bytes, 60 or so of which is stack space), which
translates into limited stack space. In order to save on stack space, I
tried to only use parameters and stack space for things which are truely
temporary. Instead of passing a pointer to a data structure which should
always be populated with data, I have the data structure declared as a
global variable and...
|
by: Michael |
last post by:
Hi newsgroup,
as the subject indicates I am looking for an advice
using global variables. I am not if this problem is more
about style then C. If its wrong in thi group, sorry.
So I have a couple of function that all need the same
information (all located in the same file). By now it looks like
/* file beginns */
|
by: vib |
last post by:
Hi there,
By chance, I came to learn that it is bad programming practice to
initialize global variables at outside of programs. Is it that bad? In
order to fullfil this, I had to declare them with const, but thereafter
they are no longer variables. Just couldn't see the benefits of this
practice. Any comments or advices are welcome.
Thanks
vib
| |
by: moxm |
last post by:
I have a statement declares a globle variable like this :
char *pname = NULL;
Then I used splint to check the code, I got errors:
err.c:8:15: Global pname initialized to null value: pname = NULL
A reference with no null annotation is assigned or initialized to
NULL. Use
/*@null@*/ to declare the reference as a possibly null pointer. (Use
|
by: zeecanvas |
last post by:
Hi,
First of all: Yes, I know global variables are bad, but I've a huge
amount of legacy code, and I've to maintain it _as_is_.
I'm maintaining a big program. I moved all (program-wide scope) global
variables outside of the files they were defined it, and created some
files that just hold global variables definitions (just variables,
without any function definition). So, depending on the purpose/category
of variables, they're defined...
|
by: Sandman |
last post by:
I dont think I understand them. I've read the section on scope in the
manual inside out.
I'm running PHP 5.2.0 Here is the code I'm working on:
//include_me.php
<?php
$MYVAR = array();
global $MYVAR, $a;
?>
|
by: Ramon |
last post by:
Is there a way to initialize the variables (or other data) of a header
file by using a function (similar to main() function)??
Thankx
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |