Peter N Lewis a écrit:
At 9:47 AM +0200 5/7/03, Maurice Lombardi wrote:
Peter N Lewis a écrit:
CodeWarrior actually would detect this and give a warning "possible use before assignment" which is very nice. CodeWarrior also detects unused parameters in procedures/functions (with an {$unused( whatever )} construct to silence the warning). These are both useful warnings, so consider it a feature request for the todo list (or wish list or whatever) if it's not already there.
use -Wall
Does not do anything for me:
program testpas9;
procedure test( a, b: Integer ); begin WriteLn( a ); end;
var i: Integer; begin Inc(i); WriteLn( i ); test( i, i * 2 ); end.
gpc -Wall -o testpas9 testpas9.pas
generates no warnings about the unused b nor any warning about the used before defined i.
with -W -Wall I obtain:
testpas9.pas:3: warning: unused parameter `b'
but nothing about i (so -Wall does not imply -W). I am baffled because I use by default -W -Wall (-Wno-identifier-case) and I receive in other programs lots of messages like:
warning: `foo' might be used uninitialized in this function
Well after some experimentation it seems that the latter works only in functions and procedures, not at the main level. Modifying your program as:
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?
Maurice