Frank Heckenbach wrote:
Gale Paeper wrote:
Joseph Oswald wrote:
The attached program demonstrates an issue with Gnu Pascal, version 20030507. The program cannot be compiled because of a non-existent "threat" on the global loop variable used in a subroutine. The main program has a loop which uses the variable, but calls no subroutines within the loop, and therefore is not vulnerable to any threat from use of that variable by other subroutines.
Attempting to compile this program results in the message
gpc -o forwarning forwarning.pas forwarning.pas: In main program: forwarning.pas:13: error: `for' loop counter is threatened in a subroutine
The program contains an error involving a for loop and when fixed GPC compiles the program with no errors. The above error message, though, is pretty misleading as to real error in the program.
Both Pascal standards specify the following requirement for for-statements:
"The control-variable shall be an entire-variable whose identifier is declared in a variable-declaration- part of the block closest-containing the for-statement."
That's another error, at least in the test program, which GPC detects with `--classic-pascal' or `--extended-pascal'.
Since my previous posting, I dug into the compiler source code and saw where GPC supports a Borland extension which relaxes the requirement.
However, AFAICS, also the error message above is correct since it's not necessary to call the routine for the error to appear:
: 6.9.3.9 Forstatements : : 6.9.3.9.1 General : : Neither : a forstatement nor any procedureand functiondeclarationpart of the : block that closestcontains a forstatement shall contain a statement : threatening (see 6.9.4) a variableaccess denoting the variable denoted by : the controlvariable of the forstatement.
In the test program, if in useloopvar you replace the loop with a simple assignment to loopvar, you have this error without the first one.
After seeing the Borland extension support, I had though of that variation but didn't get around to testing it.
This has helped clarify my understanding of controlvariable threat requirements. For some reason or other, I've never picked up the full implications of the "any procedureandfunctiondeclarationpart" part of the requirement. For-statement threat requirements is one area a lot of compilers don't even attempt to enforce. So one ends up adopting coding practices which avoids the ills the threat requirements are designed to preclude anyway.
[snip]
I tried to compile Web and TeX and noticed a few more problems, though apparently all quite minor:
Compiler directives `{$C-,A+,D-}'
`WriteLn' applied to `packed file of Char' rather than `Text'
`others:' instead of `otherwise'
`Break (FileVar)' (perhaps the same as `Page'?)
3rd parameter to `Reset' and `Rewrite'
hard-coded 'TTY:' for terminal (VMS specific?; Unix has '/dev/tty', Dos 'con')
`erstat (FileVar)' (perhaps the same as BP's `IOResult' with `{$I-}')
`breakin (FileVar)' (input flushing?)
a lot of warnings which all seem to be harmless, but point to unniceties in the code
Time for `--dec-pascal' ...?
Perhaps not. With some 'net seaching, I found a location with a set of "master files personally by Donald E. Knuth" at ftp://ctan.tug.org/tex-archive/systems/knuth/. In that file set, there are change files with comments like "Change file for GNU Pascal and Linux". Never having worked with Web and TeX code before, I don't know how much help those files will be in fixing the problems but it does seem to have a some promising potential.
Gale Paeper gpaeper@empirenet.com