Problem with putenv() in global constructor

Martin Sebor sebor@roguewave.com
Mon Jan 13 05:17:00 GMT 2003


Loren James Rittle wrote:
>>I found some strange putenv() function behavior when it's used in a
>>global object (C++ code) constructor.  I work on SPARC/Solaris 8
>>with g++/gcc version 2.95.3 20010315 (release).  [...]
> 
> 
> Hi,
> 
> This behavior is outside the scope of anything we can "fix" (unless we
> break other global constuctor-related issues).  Your report does not
> suprise me.  To be most portable, C++ programs should avoid global
> constructors that will invoke library functions traditionally callable
> only after main() has been invoked.

With all respect, that seems like a pretty vague description of such
a severe restriction -- are those functions documented anywhere?

FWIW, the "problem" seems to be caused by the gcc runtime (2.95
through 3.2) and does not appear to be C++ specific (gcc exhibits
the same behavior for functions declared with the __attribute__
((constructor)) extension). On the same system, SunPro handles
fine call to putenv() in ctors of global objects.

Regards
Martin



More information about the Gcc-bugs mailing list