|[7 earlier articles]|
|Re: Is Java useful for writing (C/C++) compiler firstname.lastname@example.org (dale) (2000-04-21)|
|Re: Is Java useful for writing (C/C++) compiler email@example.com (2000-04-21)|
|Re: Is Java useful for writing (C/C++) compiler firstname.lastname@example.org (2000-04-25)|
|Re: Is Java useful for writing (C/C++) compiler email@example.com (Jonathan Barker) (2000-04-25)|
|Re: Is Java useful for writing (C/C++) compiler firstname.lastname@example.org (Robert A Duff) (2000-04-25)|
|Re: Is Java useful for writing (C/C++) compiler email@example.com (Laurent Guerby) (2000-04-26)|
|Re: Is Java useful for writing (C/C++) compiler firstname.lastname@example.org (dale) (2000-04-27)|
|Date:||27 Apr 2000 10:53:41 -0400|
|References:||00-04-125 00-04-128 00-04-134 00-04-141 00-04-151 00-04-172|
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)
> 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
M : Month := F (3);
-cannot- cause a constraint error in assigning a value to
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
Return to the
Search the comp.compilers archives again.