This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: constructor calling order
- From: Alexander Sieb <alex at rnd dot org>
- To: harsha at vishvakannada dot com
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 20 Jan 2002 19:45:38 +0100
- Subject: Re: constructor calling order
- References: <04123725044179@MAIL.leftcoast.net>
- Reply-to: alex at rnd dot org
harsha@vishvakannada.com wrote:
>
> I have a problem with my program compiled using gcc in linux. In windows same code works fine.
>
> I have two cpp files having to global objects of two different classes
>
> I want to know which constructor is get called first ?
> how can I change the order ?
The initialization order of statics and global variables between compilation units
is undefined. So you can't change the order of initialiation of these objects in
portable manner.
It's also a good practice to minimize the use of global and static objects in general.
If you have to use them be very careful with respect to their order of initialization.
--
Regards,
Alexander