This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Global Objects initialization Problem.......
- From: Satendra Pratap <spgroups at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Wed, 27 Apr 2005 10:02:04 +0530
- Subject: Global Objects initialization Problem.......
- References: <47f703220504260548508dadec@mail.gmail.com>
- Reply-to: Satendra Pratap <spgroups at gmail dot com>
Hi,
I am using a cross compiler "sparclet-aout-gcc". I have written my own
main function and does not link to libgcc's
main function while linking is done. I m not able to initialize the
global objects
The generated executable format is "a.out".
For example:
when I execute the following program I got printed 0 while It should
be 4321..and the printf inside
constructor of class A is executed not at all...
class A{
public:
int a;
A(int id) { a=1234;
printf("The constructor ID=%d \n", id);
};
};
A out(4321); // global
int main()
{
printf("The constructor ID in MAIN = %d \n", out.a);
}
The code (That resides in my main function) That I used for initialization is:
extern func_ptr __CTOR_LIST__[];
extern func_ptr __DTOR_LIST__[];
Void CppGlobalInit()
{
unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];
unsigned i;
if (nptrs == (unsigned long)-1)
for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);
for (i = nptrs; i >= 1; i--)
__CTOR_LIST__[i] ();
}
Waiting for a solution........
Thanks
Satendra