Re: compiling C++ to C, was writing a compiler

Louis Krupp <>
Wed, 05 Nov 2008 12:12:48 -0700

          From comp.compilers

Related articles
[5 earlier articles]
Re: Writing a compiler (Marco van de Voort) (2008-11-02)
Re: Writing a compiler (Louis Krupp) (2008-11-03)
Re: Writing a compiler (Alex Colvin) (2008-11-03)
Re: compiling C++ to C, was writing a compiler (Marco van de Voort) (2008-11-04)
Re: compiling C++ to C, was writing a compiler (Alex Colvin) (2008-11-04)
Re: compiling C++ to C, was writing a compiler (Barry Kelly) (2008-11-05)
Re: compiling C++ to C, was writing a compiler (Louis Krupp) (2008-11-05)
| List of all articles for this month |

From: Louis Krupp <>
Newsgroups: comp.compilers
Date: Wed, 05 Nov 2008 12:12:48 -0700
Organization: Compilers Central
References: 08-10-037 08-10-046 08-10-047 08-11-003 08-11-008 08-11-009 08-11-014 08-11-015 08-11-019
Keywords: C++, history
Posted-Date: 05 Nov 2008 18:50:05 EST

Marco van de Voort wrote:
> On 2008-11-03, Alex Colvin <> wrote:
>>> Tony said, "From what I've read, it seems that CFront couldn't implement
>>> the whole language."
>>> I said I thought it could, at least theoretically, although modern
>>> compilers which implement the current standard all compile to machine code.
>> Runtime and linker features such as exceptions and template instantiation
>> would be very difficult to generate in C.
> Templates are no problem, the C++ compiler instantiates them, and writes
> them out in C code.
> Exceptions are harder. Sure, it is doable in C, but would the resulting,
> stack unwinding C be portable to a different compiler (IOW free of (ab)use of
> specific ABI knowledge )?

The cfront wikipedia entry has this to say about exceptions:

"Cfront 4.0 was abandoned after a failed attempt to add exception
support, and it appears it is no longer commercially available. The C++
language had grown beyond its capabilities, however a compiler with
similar approach became available later, namely Comeau C/C++, which is
considered highly standard compliant."

And on the Comeau website,>compiler

says this:

"The C compiler is used merely and only for the sake of obtaining native
code generation. This means that Comeau C++ is tailored for use with
specific C compilers on each respective platform. Please note that it is
a requirement that tailoring must be done by Comeau. Otherwise, the
generated C code is meaningless as it is tied to a specific platform
(where platform includes at least the CPU, OS, and C compiler) and
furthermore, the generated C code is not standalone. Therefore, it
cannot be used by itself (note that this is both a technical and legal
requirement when using Comeau C++), and this is why there is not
normally an option to see the generated C code: it's almost always
unhelpful and the compile process, including its generation, should be
considered as internal phases of translation."

So it sounds like Tony and Marco are basically right: cfront as we knew
it can't do exceptions.

Templates are a challenge for any compiler, cfront or not. Back in 1994
and 1995, I was making a living porting C++ code to DEC C++ (which at
the time didn't support automatic template instantiation) and to Sun C++
(whose old cfront compiler did it well but whose brand new native
compiler did it badly). I eventually wrote something using nm and perl
which kept track of which templates were needed and compiled them (with
C++), iterating until there were no more uninstantiated templates left.

I think I still have a copy of that code somewhere.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.