Re: Which target language do I choose?

mark@msm.cam.ac.uk (Mark Manning for ftp)
24 Jul 1998 12:28:17 -0400

          From comp.compilers

Related articles
Which target language do I choose? Thomas.Mork.Farrelly@nho.hydro.com (Thomas Mork Farrelly) (1998-07-10)
Re: Which target language do I choose? henry@spsystems.net (1998-07-13)
Re: Which target language do I choose? wclodius@aol.com (1998-07-17)
Re: Which target language do I choose? andrew@openkast.com (Andrew Cruickshank) (1998-07-17)
Re: Which target language do I choose? toon@moene.indiv.nluug.nl (Toon Moene) (1998-07-20)
Re: Which target language do I choose? conway@cs.mu.OZ.AU (1998-07-20)
Re: Which target language do I choose? albaugh@agames.com (1998-07-20)
Re: Which target language do I choose? mark@msm.cam.ac.uk (1998-07-24)
Re: Which target language do I choose? cts@bangkok.office.cdsnet.net (1998-07-26)
Re: Which target language do I choose? henry@spsystems.net (1998-07-27)
Re: Which target language do I choose? lkrupp@netONE.com (Louis Krupp) (1998-07-30)
| List of all articles for this month |
From: mark@msm.cam.ac.uk (Mark Manning for ftp)
Newsgroups: comp.compilers
Date: 24 Jul 1998 12:28:17 -0400
Organization: University of Cambridge, England
References: 98-07-109 98-07-123 98-07-149
Keywords: portable, C, practice

Mike Albaugh (albaugh@agames.com) wrote (inter alia):


: I'll admit that I occasionally have to take "C" code that was written
: with "gcc extension" and make it "really C"... With the exception
: of alloca() (Devil's spawn :-) and labels-as-goto-pointers,
: [w]hich of the extensions do you really find indispensible?


          I'm currently writing a BCPL-to-C translator, which I suppose one
might think of as "up-compilation", given that C was based on the
typeless BCPL language. Doing this properly has turned out to be
surprisingly interesting.


          In BCPL, the expression primary:


          table <value1>, <value2>, ... <valueN>


          returns a static vector of N words initialised so that the first
word is value1, the second value2, and so on. value1 .. valueN must
all be evaluable at compile time. An easy way to code this in GNU C
is to use the ({ .. }) extension (which allows several statements
between the two brackets, and yields an expression which is the value
of the last one):


          ({
static int x [] = { <value1>, ... <valueN> };
/* convert to word address on 32-bit machine */
(int) x>>2;
          })


          I can't immediately see any simple way of doing this in ANSI C.
About the only thing I can think of doing is declaring a function
which returns the appropriate value; the problem here is that
(a) we are in an expression, so declarations aren't allowed, so the
function must be declared before the current function; (b) the values,
though constant, could still depend on manifest constants which are
in scope only in the current function. It *would* be possible to
implement this in ANSI C, but it would be *really* messy! BCPL valof
expressions also benefit from similar treatment.


          GCC, like BCPL, also allows nested function declarations; again,
this *can* be got round, but again only messily.


          Mark


Mark Manning, Computer Associate, Dept of Materials Science, Cambridge
+44 1223 334369 mrm1@msm.cam.ac.uk
--


Post a followup to this message

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