This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
When to use if-if, else-if, switch, goto and local scope vars?
- From: lynx dot abraxas at freenet dot de
- To: gcc-help at gcc dot gnu dot org
- Date: Sun, 23 Sep 2007 12:46:59 +0200
- Subject: When to use if-if, else-if, switch, goto and local scope vars?
Hello!
Im programming an avr microcontroller in pure C at the moment and am close to
run out of memory and cycles. So I did some research on optimization. The
problem is there are so many articles and hints that do not state the same and
do not clearly point out what is valid for pure C. So I'd like to know:
- when to use switch instead of else-if statments
- how many cases there have to be for switch to be better than else-if?
- is an if-if statement better than if-else-if or switch when it is an
exclusive decission?
- is it better to nest switch statement or use else-if instead of nesting?
- does it save RAM when I define variables in the innermost scope possible?
- when does it help writing out loops?
- should I concider using banned goto instructions for microcontrollers?
Thanks for Your answers.
Lynx