CBFalconer wrote:
Frank Heckenbach wrote:
Martin G C Davies wrote:
gpc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.6/2.8.1/specs gpc version 20011222, based on gcc-2.8.1
I have to use gcc-2.8.1 because later versions have a bug with goto out multiple levels (as discussed in this forum before).
My new problem is with source:-
program Hello ;
function covers( var p1 , p2 : integer ) : boolean ; begin if ( p1 = p2 ) then begin covers := false ; writeln( 'mgcd covers returns false 1' ) ; return ; end ;
covers := true ; writeln( 'mgcd covers returns true' ) ;
end ;
var i1, i2 : integer ; begin i1 := 1 ; i2 := 1 ; writeln( 'covers=' , covers( i1 , i2 ) ) ; end.
When I run it I get:-
mgcd covers returns false 1 covers=True
I could not find a reference to this problem. The problem was not introduced in 20011222 because 20010924 shows the same problem.
You use `Return' without parameters which returns an arbitrary (undefined) value. If you compile with `-Wall' (always recommended), you'll see this problem immediately.
You can use `Exit' instead of `Return' to avoid this problem. Both are non-standard, BTW (`Exit' comaptible to BP, `Return' to C-; and perhaps some other Pascal compilers). The "clean" solution, and very easy to do here, would be to use an `else' branch.
AFAIK this usage is not condoned by any Pascal standard, and should be discouraged for just this sort of reason. Would it be possible to collect such things and emit warnings for them unless they have been specifically enabled, for example by the --BP?? flag for exit. This would discourage people from using such unsafe mechanisms, and still meet your objectives of compiling anything from anywhere :-)
I think there are two different issues:
- This particular usage of `Return' without a parameter in a function. That's simply wrong, and GPC will flag it as an error in the future.
- Use of `Return' and `Exit' in general. Indeed, Pascal standards don't condone them -- not because of this particular problem but because of the "single exit" philosophy. -- OTOH, they have `goto', and (EP only, IIRC) `Halt' which also contradict this philosophy. A main reason often given for the existence of `goto' is the nonlocal usage to return from nested routines, and in my experience those situations can often be adequately dealt with using `Exit'; and `Exit' is still "cleaner" in a way than `goto' which can jump in the middle of an outer procedure, whereas `Exit' at least returns to where it was called from. Well, we could keep arguing about these points, but the bottom line is: GPC's design principle is, allow for all reasonable extensions (and some not so reasonable ones ;-) by default, and forbid them with `--extended-pascal' etc. That's exactly what it does here, i.e. in EP mode, `Exit' and `Return' are simply unknown identifiers.
Frank