Finding unused variables

So I've finally finished my coding for my project and I'm busy tiding up my code. I was wonder if Arduino has a explicit option like VB.net or some other option to let you know if you have variables defined that you aren't using?

Is there such a option?

IDE version?

The latest - v1.0

• Start the Arduino IDE • Click the [u]File[/u] menu item then click [u]Preferences[/u] • Ensure [u]Show verbose output during: compilation[/u] is checked • Click [u]OK[/u]

Test sketch...

void setup( void )
{
  int notused;
}

void loop( void )
{
}

Result...

sketch_feb17a.cpp: In function 'void setup()':
sketch_feb17a.cpp:7: warning: unused variable 'notused'

Thanks - as easy as that.

It works finding for unused variables declared in a void, but not if you declare a variable outside of it. Eg I put

int test = 1;

before the:

void setup() {                
   
}

And it does not report that its unused.

Put static in front of the variable definition.

Awesome - thanks. That did it.

declared in a void,

They're called "functions", not "void"s. If the function returned an "int", you wouldn't call it an "int"

Cool - another learnt tonight :)

Keep in mind also that the compiler is going to do away with unused variables under the hood. I applaud your desire to keep your code clean however, it definitely promotes better code to do things like that.

It works finding for unused variables declared in a void, but not if you declare a variable outside of it. Eg I put And it does not report that its unused.

That's because it is not unused. If you explicitly define a value, you are using the variable.

If you know what value the variable should have, then you know that you are going to use it.