Compiler Warning and Notices like unused variables etc.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Compiler Warning and Notices like unused variables etc.

Jason P Sage
I just wanted to say I LOVE the fact that the compiler warns you of these
mundane details.

Personally, I don't consider my application at a good stopping point unless
I can make all the warnings go away. Sometimes I even will put in (hopefully
a low overhead thing when I do it)  a meaningless command to remove
"variable not initialized" warnings... when I KNOW I'm doing something to
init the variable that the compiler can't (nor is expected to) know I'm
doing that.

Example:

Procedure HiWorld;
Var MyVariable: ansistring;

Begin
  MyVariable:=MyVariable; // this is a workaround in rare cases.
  CallAReferenceProcedure(MyVariable); // This is warning material.
End;

Note: I know it MAY create a few assembly instructions - but I think I'll
take a couple of them to hush the compiler.

It seems like a "CLEAN" thing to do... I mean, it raises doubt (speaking for
myself) when I compile something and there are warnings being displayed. It
makes me think the programmer has not addressed everything or my environment
might be the cause of said application to maybe not work as designed.

Jason P Sage

 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Compiler Warning and Notices like unused variables etc.

Graeme Geldenhuys-2
>   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?  I have been trying for a
long time to figure out a clean way of getting rid of some compiler
warnings.

Regards,
  Graeme.


--
There's no place like 127.0.0.1
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Compiler Warning and Notices like unused variables etc.

Vinzent Höfler
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}"?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Compiler Warning and Notices like unused variables etc.

Michael Van Canneyt
In reply to this post by Graeme Geldenhuys-2


On Wed, 26 Jul 2006, 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 will.

> I have been trying for a
> long time to figure out a clean way of getting rid of some compiler
> warnings.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal