[comp.lang.c++] Strange Constructor Problem : More Information

ashley@usage.csd.oz (Ashley Aitken) (06/21/91)

From article <727@spinifex.eecs.unsw.oz>, by ashley@spinifex.eecs.unsw.oz (Ashley Aitken):
> The problem is that when the program runs it DOES NOT CALL THE CONSTRUCTORS
> FOR THE GLOBAL OBJECTS before (or after) it starts in the main program.
> 

I have narrowed the problem down a lot but still cannot see
what the problem is. Arrgghhh.

File1:

	class A { ... } // Constructor and Destructor
	A a;

	class B { ... } // Constructor and Destructor

	class C { ... } // Constructor and Destructor
	extern C c;

	main() {
		B b;
	}

File2:

	class C { ... } // Constructor and Destructor
	C c;


When  File1 is compiled on its own the constructor for a is
called before the main starts etc. As expected.

However, if File2 is compiled and linked in and it is first
to the linked then the constructor for a is not called
at all!
	
If File2 is compiled and linked in but File1 is first to be
linked then the constructor for a is called but not the 
constructor for d.

What is the story?

It seemed to occur with Version 1.2.1 and Version 2.0. Seems
to me to have something to do with linking the STI-functions
together via the LINK structure. 

Is this the responsiblility of mxx/c++patch?

I was under the impression all of the constructors would be
called before the main program.

What could be happening to cause this? 

Am I mad?

Any information which can enlighten me on this subject will
be most appreciated. Please e-mail me (as well if you post)
as I don't want to miss any answers.

Thanks in Advance,
Ashley Aitken.
ashley@spectrum.cs.unsw.oz.au