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'.
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 ForÂstatements : : 6.9.3.9.1 General : : Neither : a forÂstatement nor any procedureÂand functionÂdeclarationÂpart of the : block that closestÂcontains a forÂstatement shall contain a statement : threatening (see 6.9.4) a variableÂaccess denoting the variable denoted by : the controlÂvariable of the forÂstatement.
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.
This usage is present in Donald E. Knuth's WEB and TeX programs, and requires changing these loops to use unique loop variables.
If there is a way to disable this check, I cannot find it in the documentation.
Currently `--borland-pascal' or `--delphi' will turn it into a warning only (though `--borland-pascal' is probably not really the best dialect to compile TeX, it actually doesn't seem to cause more problems at first glance).
This isn't the first time nor will it be the last time when porting a program to a different compiler uncovers latent errors in a program.
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' ...?
In the area of for-statements, there are latent errors in quite a few programs since there are quite a few compilers around which don't enforce all the for-statement requirements.
Seems quite so. (GPC does one or two more now, but still not all.)
Frank