This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Global Objects initialization Problem.......


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] ();

}

I m not running collect2, just calling a function CppGlobalInit() from
main to initialization Of global constructors...., I m using my own
linker scripts which I have
put the command CONSTRUCTORS in.


Waiting for a solution........
Thanks
Satendra


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]