Path: utzoo!attcan!uunet!tektronix!tekcrl!tekfdi!videovax!bart From: bart@videovax.tv.Tek.com (Bart Massey) Newsgroups: comp.lang.c++ Subject: Re: C++ --> C Message-ID: <5408@videovax.tv.Tek.com> Date: 17 Apr 89 08:44:09 GMT References: <173@cs.columbia.edu> <7050005@hpcupt1.HP.COM> <9204@alice.UUCP> Reply-To: bart@videovax.tv.tek.com (Bart Massey) Organization: Tektronix TV Measurement Systems, Beaverton OR Lines: 42 In article <9204@alice.UUCP> ark@alice.UUCP (Andrew Koenig) writes: > > Why do pepole say that a compiler that produces C as its > object code isn't a `true compiler' but a compiler that > produces assembly language is? Do you think it's significantly > easier to translate C++ into C than into assembly language? > > [answer: it isn't -- but it certainly is easier to translate > C++ into C that will run on a dozen different machines than it > is to translate C++ into a dozen different assembly languages!] Conjecture: Perhaps because they have ATT cfront as their sole example of C++ --> C translation? One way of looking at it is that cfront is a compromise between two distinct design goals: (1) produce "correct", efficient C code from C++ code, and (2) produce C code which is as much like the original C++ code as possible, and thus is still fairly "human-readable". Most "true" compilers are only concerned with (1). Note that (2) is much easier than (1), for translations to both C and assembly language. For example, people say that inline functions in G++ are "compiled in", whereas they don't tend to say this about inlines in cfront. This is because G++ inserts code with the appropriate semantics inline, whereas cfront attempts to simply copy the appropriate code in without fully understanding its semantics, thus introducing significant restrictions in "inlineability". My definition of "true" compilation would involve the process of semantic analysis followed by "from scratch" code generation. One can imagine writing a back-end for GNU G++ which produced C-code (in fact some friends and I have partially completed such a beast). I would call this hypothetical machine a "true" compiler, but cfront a "translator", though they both translate C++ to C. Bart Massey ..tektronix!videovax.tek.com!bart ..tektronix!reed.bitnet!bart DISCLAIMER: The above is not intended to imply that there's anything wrong with cfront -- there are situations in which it is much more useful than a "true" compiler. It is merely intended to point out distinctions between cfront and "true" compilers.