Re: C as assembly language

fjh@cs.mu.OZ.AU (Fergus Henderson)
12 Apr 2001 02:46:40 -0400

          From comp.compilers

Related articles
[4 earlier articles]
Re: C as assembly language eodell@c1220335-a.potlnd1.or.home.com (2001-04-10)
Re: C as assembly language andi@complang.tuwien.ac.at (2001-04-10)
Re: C as assembly language jmorris2@twcny.rr.com (Morrisett) (2001-04-10)
Re: C as assembly language jacob@jacob.remcomp.fr (jacob navia) (2001-04-10)
Re: C as assembly language felixundduni@freenet.de (felix) (2001-04-10)
Re: C as assembly language fjh@cs.mu.OZ.AU (2001-04-10)
Re: C as assembly language fjh@cs.mu.OZ.AU (2001-04-12)
Re: C as assembly language vbdis@aol.com (2001-04-12)
Re: C as assembly language felixundduni@freenet.de (felix) (2001-04-14)
Re: C as assembly language fjh@cs.mu.OZ.AU (2001-04-14)
Re: C as assembly language rhyde@transdimension.com (Randall Hyde) (2001-04-14)
Re: C as assembly language vbdis@aol.com (2001-04-15)
Re: C as assembly language jim.granville@designtools.co.nz (Jim Granville) (2001-04-18)
[6 later articles]
| List of all articles for this month |
From: fjh@cs.mu.OZ.AU (Fergus Henderson)
Newsgroups: comp.compilers
Date: 12 Apr 2001 02:46:40 -0400
Organization: Computer Science, University of Melbourne
References: 01-03-006 01-03-046 01-03-130 01-04-027 01-04-055
Keywords: C, GCC
Posted-Date: 12 Apr 2001 02:46:40 EDT

"jacob navia" <jacob@jacob.remcomp.fr> writes:


>I would like to point out that some of the problems of C as an
>assembly language are just wrong, using the specific example of the
>lcc-win32 system. No environment is "perfect" but I think lcc-win32
>comes close, and is widely used as a back end compiler.
>
>> Hmm... there are a few additional cases where C is simply inappropriate:
>> 1) You want to check for integer overflow.
>
>Under lcc-win32 you just write
> c = a+b;
> if (_overflow()) {
> // Overflow handling
> }


That's not portable, though. And it's probably not very efficient
either, since you have to use lcc-win32. (How does lcc-win32 compare
to GNU C and other C compilers? The original lcc on which lcc-win32
is based generates significantly worse code than gcc.)


>> 2) You need exceptions.
>
>lcc-win32 lets you use the exceptions defined by the OS.


That's not portable, though.


>> Oh, and slightly off-topic, there are a few other things that annoy
>> those who want to use C as a backend for their compiler:
>> 3) It has no support for tail call recursion.
>
>Not very difficult to implement in the generated C with a few assignments
>and a goto...


It is indeed difficult if you want to support separate compilation,
since C doesn't allow a "goto" to jump from one function to another.
And compiling the whole source program to a single C function is
likely to cause trouble for the C compiler, either exceeding fixed
limits or getting blow-outs in compile times.


>> 6) It cannot bind global variables to registers
>In the x86, with only 6 registers this would be impossible,


Sure it would be possible. Three for the front-end compiler and three
for the C compiler, for example. That's how we do it when using GNU C
global register variables in the Mercury compiler. (In recent
versions of GNU C it doesn't work reliabily, but that's another
story... AFAIK, there's no reason why it shouldn't, just lack of
people with sufficient time and expertise to fix it).


>but in other
>architectures, the C compiler lets you assign globals to the global
>registers with some compiler specific syntax.


Only GNU C allows that, AFAIK.


>> 7) It has no support for lightweight concurrency
>
>Well, under windows you can use the thread facility of the operating system.
>Lcc-win32 supports it of course.


That's not portable, though.


If you tie yourself to lcc-win32, then you lose many of the advantages
of compiling to C.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
                                                                        | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.


Post a followup to this message

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