Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to list unused variables and functions when building for Arduino (Read 6386 times)
MCannist
Newbies
*
Offline


Posts: 2
Joined: Aug 16th, 2014
how to list unused variables and functions when building for Arduino
Aug 16th, 2014 at 5:30pm
Print Post  
Hi all.
I am building a long sketch to be run on the Arduino Pro Micro whose max program size is 28.672 bytes.

Ever since this sketch is the result of several code merges and additions, I would like to get rid of anything not actually used to clean up the code a bit and get more memory available for what I still need to add...

I searched the web but did not find anything useful.

I got some results using CppCheck from the command line in this way:

cppcheck --library=avr.cfg --enable=all  myprogram.ino

...but I would really like to get this info within the Visual Micro / VS IDE...

Any help is really appreciated.
mario
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: how to list unused variables and functions when building for Arduino
Reply #1 - Aug 16th, 2014 at 7:36pm
Print Post  
That's a good question. I think then answer is there isn't anything. Which Ide are you using there might be a plugin.

It's useful to see the cppcheck example. Maybe we can build in a way to use that it would be very useful. I'll give it some thought.

I thought that the avr linker ignores unused functions and variables?
  
Back to top
IP Logged
 
MCannist
Newbies
*
Offline


Posts: 2
Joined: Aug 16th, 2014
Re: how to list unused variables and functions when building for Arduino
Reply #2 - Aug 17th, 2014 at 9:17am
Print Post  
Hi Tim and thank you for your kind answer.
Just checked adding an array not used and seen the sketch size does not increase. So as you said the linker is not including that in the final binary.

This means that the memory usage issue is not influenced by those variables/arrays.

Looking at this from the code clean-up point of view instead, i would still like to be able to get rid of unused things in the source.

I initially tried to add
  promicro8.build.extra_flags=-Wunused
to the boards,txt file but i've seen that:
1) it seems it is not used when building (even after reloading the toolchain or re-opening the IDE)
2) it is not actually needed because i've seen  -Wall is used when I enabled the verbose output from VisualMicro
3) unused variables and functions are listed by the compiler, but ONLY if they are marked as static

IMHO the point now is that having no statics but lots of variables and functions defined that probably are not used, I cannot list them in an automated way to do my cleanup.

CppCheck is a static analysis tool and actually considers those cases in a slightly different way, listing also the non-static unused vars/funcs.
As you mentioned, I've found a plugin to use CppCheck from the VS IDE and will try it in the next days.

I think that a nice addition to Visual Micro features could be a tool to aid with such kind of code clean-up and squeezing.
Just 2 examples:

a) CppCheck listed as "unused" a function that I wrote but then forgot to use in a couple of code lines after copy/pasting from others that were using a different one. This could have been a bug to search during run time... Being not a static... the compiler did not warn about this Smiley

b) I'm using six libraries and many functions from them are contributing to the final binary size. It could be very helpful to have some sort of code map showing the size in bytes for each function/routine/code section that has been included by the linker in the final binary to understand where I actually need to shorten things a bit... Smiley

Please let me know your opinion on this.
Bye,
Mario
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12163
Location: United Kingdom
Joined: Apr 10th, 2010
Re: how to list unused variables and functions when building for Arduino
Reply #3 - Aug 17th, 2014 at 3:27pm
Print Post  
Hi,

Interesting stuff and food for thought. 

Please let us know which plugin you found if it works well for you.

Thanks for the update.

Edit: Forgot to say if you used Arduino 1.5.x with Visual Micro you can override the build properties via boards.txt/platform.txt
« Last Edit: Aug 17th, 2014 at 3:30pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint