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 would imagine a "warn(errno, otherparms)" procedure in the compiler, called for all suspicious constructs. It would be up to warn to suppress in specific configurations.
Incidentally, shouldn't the return have used the value of covers in the first place? It is not possible to write "return (covers);" because that would be a recursive call. Maybe it should have been compiled as a jump to the exit code, which is probably what you are doing for 'exit' anyway.