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

dale <dale@cs.rmit.edu.au>
27 Apr 2000 10:53:41 -0400

          From comp.compilers

Related articles
[7 earlier articles]
Re: Is Java useful for writing (C/C++) compiler dale@cs.rmit.edu.au (dale) (2000-04-21)
Re: Is Java useful for writing (C/C++) compiler dvdeug@x8b4e53cd.dhcp.okstate.edu (2000-04-21)
Re: Is Java useful for writing (C/C++) compiler nr@labrador.eecs.harvard.edu (2000-04-25)
Re: Is Java useful for writing (C/C++) compiler jandk@easynet.co.uk (Jonathan Barker) (2000-04-25)
Re: Is Java useful for writing (C/C++) compiler bobduff@world.std.com (Robert A Duff) (2000-04-25)
Re: Is Java useful for writing (C/C++) compiler guerby@acm.org (Laurent Guerby) (2000-04-26)
Re: Is Java useful for writing (C/C++) compiler dale@cs.rmit.edu.au (dale) (2000-04-27)
| List of all articles for this month |

From: dale <dale@cs.rmit.edu.au>
Newsgroups: comp.compilers
Date: 27 Apr 2000 10:53:41 -0400
Organization: rmit
References: 00-04-125 00-04-128 00-04-134 00-04-141 00-04-151 00-04-172
Keywords: design

Jonathan Barker wrote:


> A better counter-example:
> ------------------------
> Setting the value of a variable from the result of a function...
>
> for x=a to b
> Month m = f(x)
> end
>
> The compiler cannot (except in the most trivial cases)
> bound f(x) to the appropriate range just because it knows x lies
> in the range a...b. Indeed, if f is even moderately sophisticated
> it can't even tell that f will ever produce a result - you don't
> even need to use a halting problem construction...


As Laurent has already pointed out this is a flawed example, that
only shows how poor C is at modelling ranges.


In Ada you could write...


      subtype Month is Integer range 1..12;
      function F (Item : Integer) return Month;
            -- guarenteed to return a value b/w 1 & 12


so that


      M : Month := F (3);


-cannot- cause a constraint error in assigning a value to
M.


Similarly Eiffel can provide much stronger post conditions that
could be used by an optimizing compiler to eliminate other run
time checks. No doubt other languages which have a stronger type
system than either Ada or C can do much better at proving the
need for run time checks to be unnecessary.




As to whether the function ever returns a value is rather
irrelavent to the need to place a check at the call site.


Yes, the check in your example function would need to be moved
to the function body (to ensure the postcondition is met), so
we aren't gaining much here, but in other situations the compiler
can determine what is going on, and doesn't need to insert any
checks.




Dale


Post a followup to this message

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