C++ constructors
Jonathan Larmour
jlarmour@redhat.com
Wed Jun 6 10:36:00 GMT 2001
João Cadamuro Junior wrote:
>
> Hello,
>
> I have worked with GCC and G++ for "powerpc-eabi" embedded targets. In
> the last two versions of GCC (2.95.2 and 2.95.3) I have learned some
> hard things about C++ constructor and GCC.
>
> Under gcc-2.95.2 the execution order of constructors is the linkage
> order. The first file linked will construct their objects first.
>
> Under gcc-2.95.3, the behavior is the opposite. The last linked archive
> will construct their objects first.
>
> Since I want to have a c++ code to be compiled correctly independent of
> the compiler version, someone knows what can I do to force some order to
> constructors under G++?
Strictly according to the C++ standard, the execution order of constructors
is undefined.
You can control it in G++ though, by compiling with -finit-priority. Then
you can give your static objects (with constructors) a priority e.g.
static dummy_init_class dummy_init_obj
__attribute__((init_priority(10000)));
Jifl
--
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine
Come to the Red Hat TechWorld open source conference in Brussels!
Keynotes, techie talks and exhibitions http://www.redhat-techworld.com/
------
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
More information about the crossgcc
mailing list