Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!spool.mu.edu!uunet!taumet!mike From: mike@taumet.com (Michael S. Ball) Newsgroups: comp.lang.c++ Subject: Re: bug with making C++ functions have C linkage ? Message-ID: <696@taumet.com> Date: 28 Apr 91 17:49:46 GMT Article-I.D.: taumet.696 References: <1991Apr16.122905.23613@cs.nott.ac.uk> <675@taumet.com> <1991Apr22.081254@Unify.com> <306@nazgul.UUCP> Reply-To: mike@taumet.UUCP (Michael S. Ball) Organization: Taumetric Corporation, San Diego Lines: 28 In article <306@nazgul.UUCP> bright@nazgul.UUCP (Walter Bright) writes: >In article <675@taumet.com>, steve@taumet.com (Stephen Clamage) writes: >/ In general, C++ programs will require initialization of static objects >/ via their constructors at runtime; cout is such an object. The C++ >/ compiler arranges for the constructors (and destructors) to be called >/ via special code emitted in the module in which main() appears. > >This is not the way Zortech C/C++ works. There, the static constructors >are called by the startup code before main() is called, so it doesn't >matter if main() was compiled with the C or the C++ compiler. In fact In fact, C++ compilers which define their own linker format, or which have access to a linker format which provides multiple named sections (psects, etc) can and should do it this way. The Borland C++ system does exactly that, as does the Oregon Software VMS compiler. Unfortunately, the majority of the C++ implementations for other environments are forced to cope with the antequated UNIX linkers which don't give you any way to do this. It appears that ELF will finally let UNIX implementors handle initialization rationally. The consequence is that the majority of different C++ compilers require that the main program be compiled with C++, while those compilers with the largest number of instances each (MSDOS compilers) don't. On a UNIX-oriented network, Steve's comments are accurate. -- Michael S. Ball mike@taumet.com TauMetric Corporation (619)697-7607