On Thu, 4 Jun 1998, Maurice Lombardi wrote:
Peter Gerwinski a écrit:
It must be declared in the most inner enclosing block. According to BP, GPC also allows global variables here
A side remark: this is a very stupid BP extension, and it is a pity that gpc allows it (except of course in compatibility mode --borland-pascal). What are the advantages of this "extension":
- saving a word of memory, but who cares nowadays of saving a single
word of memory (I don't speak of saving storage for large arrays)
- saving some keystrokes. Many beginners would think so ...
What is the disavantage: just try the following small program to produce an infinite loop by "saving" the keystrokes to redeclare the variable "i" in the procedure "test".
This must be detected by the compiler; it is a "threatening statement" to the for-loop control variable, see section 6.9.4 (page 90) of the IEC-10206 extended pascal manual. There are also other threats to be detected, before gpc can be called a standard compiler.
I did not implement any of those, because it requires saving the context where each variable is used in order to detects it's use in some inner block, or to keep a hash of names that can currently be threatened and lookup this hash for each variable-access.
Juki jtv@hut.fi
program essai;
var i:integer;
procedure test; begin for i:=1 to 2 do writeln(i) end;
begin for i:=1 to 4 do test; end.