Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!rochester!kodak!ispd-newsserver!ism.isc.com!redwood.sos.ivy.isc.com!billri From: billri@redwood.sos.ivy.isc.com (Bill Rizzi) Newsgroups: comp.lang.c++ Subject: Re: SUMMARY: C and C++ Keywords: C++ static object construction Message-ID: <1991Apr04.195944.17095@ism.isc.com> Date: 4 Apr 91 19:59:44 GMT References: <1991Apr3.011032.14110@terminator.cc.umich.edu> <1990@godzilla.tcs.com> Sender: usenet@ism.isc.com (Ism Usenet News) Reply-To: billri@ivy.isc.com Organization: Interactive Systems Corp. Lines: 41 In article <1990@godzilla.tcs.com>, gwu@nujoizey.tcs.com (George Wu) writes: |> In article <1991Apr3.011032.14110@terminator.cc.umich.edu>, |> normanb@pinhead.citi.umich.edu (David R. Richardson) writes: |> |> Last week I asked this newsgroup for comments on combining C and |> |> C++. Here is a summary of replies: |> |> |> |> [ . . . stuff deleted . . . ] |> |> |> |> For example, cfront performs this initialization by calling a routine, |> |> "_main()". In translating your C++ code, cfront places a call to this |> |> routine right after YOUR main(). |> |> Correction: _main() is called *before* my/your main(). And to be |> entirely complete, cleanup code (destructors for static and global objects) |> need to be called when main() is finished. Actually, cfront (AT&T C++ 2.1) places the call to _main() as the first statement in the definition of C function main(). Just take a peek at the generated C code. You'll see something like: ... main(...) { _main(); ... } I don't know for sure that _main() is standard with all C++ compilers, however. Regarding destructors, the C++ library has an exit() function which takes care of this. So as you pointed out, it is important to link with the C++ libraries. If your main() function is in C, an (early) call to _main() is indeed appropriate. It is probably also a good idea to call exit() explicitly, rather than "falling off" the end of your main() function and relying on the C runtime to call exit(). Bill -- Bill Rizzi INTERACTIVE Systems Corporation billri@ivy.isc.com 26635 W. Agoura Rd, Suite 200 818-880-1200 x2110 Calabasas, CA 91302