This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.
See the CrossGCC FAQ for lots more information.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Jonathan Larmour wrote: > 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/ Thank you Jifl for your g++ tip. It is what I'm looking for, even being a "non-portable" solution. Thank you also to Mark Phillips and Bill Randle to share their solutions. Both can be applied to solve the problem. But for now I'd like to discuss a little bit more about the "-finit-priority" g++ flag. When I use this approach the only executed constructors are those who have the "__atribute__ (init_priority(x))" declared. The other "common" objects are not constructed. Does anyone know if it is a feature of the GNU C++ when the flag "-finit-priority" is set, or it is a little "bug"? Thank you again... Joćo Cadamuro Junior ------ Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/ Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |