[fpc-pascal] Compiler Warning and Notices like unused variables etc.

Vinzent Hoefler JeLlyFish.software at gmx.net
Wed Jul 26 15:11:39 CEST 2006


On Wednesday 26 July 2006 12:49, Graeme Geldenhuys wrote:

> >   MyVariable:=MyVariable; // this is a workaround in rare cases.
>
> Can anybody that knowns the internals of FPC confirm if this will
> create extra work/code for the compiler?

It does create an assignment. At least with the fpc2.0.2 version I just 
checked:

Compiled with "-al" for source lines and "-O3":

|.Ll2:
|        .stabn 68,0,10,.Ll2 - P$TEST_ASSIGN
|# [10] x := x;
|        movl    -4(%ebp),%eax

Without optimization it even generates:

|        .stabn 68,0,10,.Ll2 - P$TEST_ASSIGN
|# [10] x := x;
|        movl    -4(%ebp),%eax
|        movl    %eax,-4(%ebp)

Depending on the view point and application it might be negligible. It's 
probably not a good idea to do that inside a tight loop, but in most 
other cases those couple of bytes won't hurt.

Although, well ... I wouldn't depend on that behaviour, because the 
variable still *is* as uninitialized as before, because the right hand 
side of the expression assigned to it is. So if someone cares to write 
code for a more stricter data flow analysis, the warning may at some 
time reappear.

So this is no clean way to do it I'd say.

What is needed is a way to tell the compiler: "Trust me. I know what I'm 
doing."[1] ;)


Vinzent.

[1] "{$SLEDGE_HAMMER ON}"?




More information about the fpc-pascal mailing list