egcs 1.1b: no global ctor called if main in namespace

Yves Bastide stid@lminux.univ-bpclermont.fr
Tue Oct 13 11:54:00 GMT 1998


Hi,

On a powerpc-ibm-aix4.1.5.0, putting the main() function
into a namespace (other than the specially handled std)
prevents the constructors of global variables from being
called.

Example:
#include <string>
#include <iostream>

class foo {
public:
  foo() { std::cout << "Howdy?" << endl; } // not called
};

std::string bar;

foo baz;

namespace {

main()
{
  std::cout << "zz" << endl;
  bar="Don't dump!"; // dump core (bar.rep == 0)
}

}

This code works on i586-linux, though.

(OK, I won't swear this code is legal... :-)

Yves


Well, I don't



More information about the Gcc-bugs mailing list