Dave Hansen wrote:
[...]
I don't remember the code. Was the function declared static? If not, the compiler must generate at least the ret since functions external to the file could potentially call it as well. If the function was static, the code for it (and the calls to it) could indeed be removed entirely.

This is even better with "new and improved compilers": even if you don't declare the function static, but you compile your project with "-combine -fwhole-program", the compiler can still through it away entirely :)

For instance, I have a small project with several c modules, that when compiled with "-combine -fwhole-program" creates a 3kb .text section. If I place a "return 0" at the top of main, the compiler optimizes almost everything away and produces a 180 bytes .text section. Only the interrupt handlers survive, because we told the compiler explicitly not to through them away.

Note that I'm not advocating for not declaring static functions that should be static. Only that functions that can't be static because are used from outside its module can still be optimized by the compiler with this option.

The only downside is that this basically makes the compiler compile the entire project at once instead of just the modules with changes. For small projects, this isn't too bad at all, and for big projects you can do it for just the "final version".

--
Paulo Marques
Software Development Department - Grupo PIE, S.A.
Phone: +351 252 290600, Fax: +351 252 290601
Web: www.grupopie.com

"All I ask is a chance to prove that money can't make me happy."



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to