Newsgroups: comp.lang.c++ Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!rice!cooker From: cooker@newsrice.edu (Donald George Baker) Subject: Re: Mixing C with C++ Message-ID: <1991Apr24.161641.5083@rice.edu> Originator: cooker@vancouver.rice.edu Sender: news@rice.edu (News) Reply-To: cooker@newsrice.edu (Donald George Baker) Organization: Rice University References: <1991Apr22.064847.16929@cs.nott.ac.uk> <1991Apr23.133931.6716@ssd.kodak.com> Date: Wed, 24 Apr 91 16:16:41 GMT In article <1991Apr23.133931.6716@ssd.kodak.com>, strollo@ssd.kodak.com (larry strollo ) writes: |> |> I'm confused. Since the linker is just linking object files (generated |> from C I might add), what is special about the C++ "linker" ? Do you |> really mean that some special C++ libraries are linked in (in which case I |> should be able to do the same thing by just explicitly calling out the |> libraries in the link command, shouldn't I) ? I can see that there is still a lot of confusion about what is happening with the C++ linker and how it relates to mixing in pure C code. Besides linking against the C++ library, the linker does the interesting part of getting the constructors and destructors for global objects called at the right time. Note: these comments refer to AT&T's CFront, so your milage may vary. The C++ linker actually links a program twice. The first time to make an executable on which 'nm' can be run. The second pass looks for routines that follow a particular naming convention. These routines are the constructors and destructors for global objects. The routines are gathered up and put into two tables. The order in which these appear is totally dependent on the linking order--a serious problem with global objects. A routine called _main will call all of the constructors and _exit (I think) calls all of the destructors. It is hard not to have the destructors called, because you must link against the special _exit, but when your main program is not C++, _main does not get called automatically. All you need to do is call _main() with no arguments yourself. I hope this helps. ----------------------------------------------------------------------------- Donald G. Baker (cooker@Rice.edu) \ Computer Science Department, Computer-human interaction, \ Rice University Programming environments, /\ P. O. Box 1892 Software engineering / \ Houston, TX 77251-1892, USA ----------------------------------------------------------------------------- -- ----------------------------------------------------------------------------- Donald G. Baker (cooker@Rice.edu) \ Computer Science Department, Computer-human interaction, \ Rice University Programming environments, /\ P. O. Box 1892