Re: Is Java useful for writing (C/C++) compiler

Laurent Guerby <>
26 Apr 2000 02:43:47 -0400

          From comp.compilers

Related articles
[6 earlier articles]
Re: Is Java useful for writing (C/C++) compiler (Jonathan Barker) (2000-04-20)
Re: Is Java useful for writing (C/C++) compiler (dale) (2000-04-21)
Re: Is Java useful for writing (C/C++) compiler (2000-04-21)
Re: Is Java useful for writing (C/C++) compiler (2000-04-25)
Re: Is Java useful for writing (C/C++) compiler (Jonathan Barker) (2000-04-25)
Re: Is Java useful for writing (C/C++) compiler (Robert A Duff) (2000-04-25)
Re: Is Java useful for writing (C/C++) compiler (Laurent Guerby) (2000-04-26)
Re: Is Java useful for writing (C/C++) compiler (dale) (2000-04-27)
| List of all articles for this month |

From: Laurent Guerby <>
Newsgroups: comp.compilers
Date: 26 Apr 2000 02:43:47 -0400
Organization: Club-Internet (France)
References: 00-04-125 00-04-128 00-04-134 00-04-141 00-04-151 00-04-172
Keywords: Java, C

"Jonathan Barker" <> writes:
> Kees, sorry for hijacking your thread.
> Dale wrote:
> > [...]It obviously depends on how much you tell the compiler. If you provide
> > range information in Ada (e.g. subtype Month is Integer range 1..12)
> > then you can obviously eliminate all checks in an appropriate for
> > loop.
> I'm not really disputing what you say, but this is really a much more
> difficult problem than you imply. "Appropriate" is the key word here -
> giving the compiler the index range only solves the problem in the
> most trivial cases.

The relevant keyword for good optimization of checks is "common"
(case). Of course as you pointed out it is easy to write "trivial"
functions where a compiler cannot remove checks without solving really
hard problems, but one want a compiler to remove as many checks as
possible where it hurts performance, and it is easy to do in the
common cases (ie loops) for languages that provide range'd integers.

For checks your compiler cannot suppress however smart, the Ada
language provides a compiler directive (pragma) that you can insert in
your source code to disable specific language checks, and of course if
you're serious, such a directive will be accompanied by a comment (or
a reference) to an explanation of why it is safe to suppress checks

(If you want to go all the way down to formal proof, see the SPARK 95
Ada subset which is designed to be able to write code where no check
is needed, ISBN 0201175177, John Barnes).

> int f(x)

In a strongly typed language such as Ada, a more appropriate
specification for this function would be

      function F (X : in Whatever) return Month;

And the compiler will easily be able to remove the check in your call
inside the loop (if the loop is over Whatever'Range it will even
remove the check for argument passing leaving no checks at all). Of
course, the smart check removal is left to F implementor, but well,
that's where it belongs.

(The GNU Ada 95 compiler GNAT has a pretty elaborate check removing
circuitery, if you want to look at it, what I'm talking about is not
Science Fiction.)

For data coming out of the external world, Ada provides an attribute
('Valid) so you can check explicitely wether a value is in range
without getting caught.
Laurent Guerby <>

Post a followup to this message

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