This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: C++ Static Variable Initialization
- To: "'Alexandre Oliva'" <aoliva at redhat dot com>, "Sarangdhar, NitinX" <nitinx dot sarangdhar at intel dot com>
- Subject: RE: C++ Static Variable Initialization
- From: "Sarangdhar, NitinX" <nitinx dot sarangdhar at intel dot com>
- Date: Fri, 17 Aug 2001 13:45:17 -0700
- Cc: "'gcc at gcc dot gnu dot org'" <gcc at gcc dot gnu dot org>
Thanks for your response. I do not have a main() program. I am creating a
shared library using g++. This shared library gets called from an existing
commercial application hence I do not have control over it.
As I understand the process, g++ emits magic during main() call to
initialize "static const" variables to their defined value. I have seen that
if the variables do not get initialized proeprly specifically if they are of
string type. I have found out that the reason for this is absence of main()
in my program, where these variables are supposed to be initialized.
After reading some reference books, I have found out that there may be a
compiler dependent procedure that I can call to initialize these variable.
Specifically since I am using g++ compiler, what function call can I make to
intialize all my static const string variables properly.
-----Original Message-----
From: Alexandre Oliva [mailto:aoliva@redhat.com]
Sent: Thursday, August 16, 2001 6:28 PM
To: Sarangdhar, NitinX
Cc: 'gcc@gcc.gnu.org'
Subject: Re: C++ Static Variable Initialization
On Aug 14, 2001, "Sarangdhar, NitinX" <nitinx.sarangdhar@intel.com> wrote:
> I have a C++ code with some static declarations. In the absence of main()
is
> there a way to initialize the statics properly?
What appears to be the problem? g++ does emit magic to get C++
globals initialized if you link in the gcc run-time object files,
which are implicitly linked in when you use g++ for linking.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me