Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!brunix!sdm From: sdm@cs.brown.edu (Scott Meyers) Newsgroups: comp.lang.c++ Subject: Re: Mixing C and C++ Message-ID: <72158@brunix.UUCP> Date: 15 Apr 91 16:51:54 GMT References: <72092@brunix.UUCP> <670@taumet.com> Sender: news@brunix.UUCP Reply-To: sdm@cs.brown.edu (Scott Meyers) Organization: Brown University Department of Computer Science Lines: 38 In article <670@taumet.com> steve@taumet.com (Stephen Clamage) writes: | What you describe is common in implementations of C++, but does not | usually apply to C. C++ allows specification of runtime code to | be executed (conceptually) before main(), and (conceptually) after | main() exits. C provides no such facility to the C programmer, and | it is unusual for a C compiler to require that main() be compiled by | that C compiler (but some have that requirement for other reasons). | | Of the C++ object-code compilers I am familiar with, all provide a | companion C compiler, and none have any requirement on main() that | would prevent mixing C and C++ code. Some C++ object-code compilers | do not even require main() to be written in C++. | | So: is your question theoretical, or do you actually have separate C and | C++ compilers which each require main() to be compiled by that compiler? My question is theoretical (i.e., I don't have a particular problem right now), but of importance because of portability: just because one or two combinations of C and C++ work together, does that mean I can sleep soundly at night before porting to a new platform with a new pair of compilers? As an example, suppose I have the following in C: const x = 10; /* global */ int y = x + 1; /* global */ A good C compiler will do the arithmetic at compile time, but I don't think the language requires that. If not, then sometime before main there has to be the computation of x+1 to initialize y. Or am I missing the point entirely? Thanks, Scott ------------------------------------------------------------------------------- What do you say to a convicted felon in Providence? "Hello, Mr. Mayor."