Maurice Lombardi wrote:
program testpas10;
procedure test( a, b: Integer ); var j: integer; begin WriteLn( a, j); end;
var i: Integer; begin Inc( i ); WriteLn( i ); test( i, i * 2 ); end.
I obtain with -W -Wall
testpas9.pas: In procedure `test': testpas9.pas:3: warning: unused parameter `b' testpas9.pas:5: warning: `j' might be used uninitialized in this function testpas9.pas: In main program: testpas9.pas:5: warning: `j' might be used uninitialized in this function
(not `i' in the last message).
I see no reason for that behavior: bug?
That's a limitation of the backend. It recognizes such problems when analyzing variable usage when optimizing (therefore this warning appears only with `-O'), and it does so only on a per-routine basis.
You can get the warning by declaring `i' in the statement part of the main program (GPC extension), so it becomes really local.
Alternatively, we could (internally) make all global declarations local to the main program. However, this would mean that, e.g. all global variables would be allocated on the stack and all global routines, when used as procedural parameters/variables, would be called through trampolines. Given the stack size limitations and trampoline bugs on some systems, I don't think that would be useful.
Frank