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". -------------------------- 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. -------------------------- In real life programming finding such a bug in the middle of a few thousand lines program is usually a headache, especially because the fact that something goes wrong is not so obvious. And who has never used small identifiers as mute variables in for loops. Creators of pascal have "thought" to ways of avoiding stupids bugs. It seems that the ideal of many programmers is FORTRAN, whose "advantage" is to "save declarations of variables". Have you ever programmed with such an efficient bug generator? I begun with that.