... strange behavour

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux