public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* ... strange behavour
@ 2005-01-29 20:36 Antonio Coralles
  0 siblings, 0 replies; only message in thread
From: Antonio Coralles @ 2005-01-29 20:36 UTC (permalink / raw)
  To: gcc-help

I'm writing on a C++ program which can be very roughly structured into 
CORE, MISC and INTERFACE. MISC depends on CORE and INTERFACE  needs both 
MISC and CORE. Consider MAIN as the object containing my main function. 
Now the tratitional approach to build this program should be

compile CORE - compile MISC - compile INTERFACE - compile MAIN  - link  
MAIN INTERFACE MISC CORE .

While this seems to work in the first place, the program doesn't really 
function when built this way. Sometimes it freezes, sometimes it 
segfaults. When I try link MAIN CORE INTERFACE MISC the linker complains 
about lot's of undefined referneces, which seems logical, as INTERFACE 
depends on CORE. But now here is what I really call strange: When I make 
a completly senseless call to one of the most advanced components of 
CORE in MAIN, then not only link MAIN INTERFACE MISC CORE works, but 
also my program - at least as long as I comile without optimisation.

Now one may ask if I use some global variables, which may be 
uninitialized under some circumstances. But the only global variable I 
use appearently works fine. The next thing one may think of are static 
variables in classes. Well, I used them - but replaced them with the 
following technique -

class foo
{
    static bar s_bar;
};
bar foo::s_bar;  //assuming bar has a default ctor

goes to

class foo
{
    static bar& getBar();
};
bar& foo::getBar() { static bar mBar; return mBar; }

without succes.

Maybe someone experienced similar problems and can give my some hints. 
If this question is considered not to fit in this list, it would be nice 
if somebody can tell me a better place to ask this question.

Thanks,
                antonio

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-01-29 20:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-29 20:36 ... strange behavour Antonio Coralles

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).