avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Re: C vs. assembly performance


From: Georg-Johann Lay
Subject: Re: [avr-gcc-list] Re: C vs. assembly performance
Date: Sun, 01 Mar 2009 11:20:36 +0100
User-agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)

Vincent Trouilliez schrieb:
On Sat, 28 Feb 2009 19:09:13 -0700
"Weddington, Eric" <address@hidden> wrote:

So in application code I tend to avoid switch statements for embedded systems, 
unless I'm writing throw-away code or the application is trivial.

Oh no ! ;-)
I have only recently got round to using switch statements, to improve
code legibility. In my current/first embedded project, I happen to have
a very long (25 cases, 160 lines long) switch statement.. I dread to
think what it would like if I had to replace it (what else with ?) with
nested if's !
How readable would that be... not to mention that with indentation, 25
levels of nesting would mean the last case would be 3 meters on the far
right... ;-)

Any coding tips to make all this look about readable by human
beings ?! ;-/
You can write

if ()
{}
else if ()
{}
else if ()
{}
...
else
{}

instead of

if ()
{}
else
    if ()
    {}
    else
        if ()
        {}
           ...
                       else
                       {}

(Optionally with one more level of {} in each but the last else)
In fact, editors like emacs will indent the two sources differently, i.e. just in the way I indicated, even though there is absolutely no difference in semantic. And the first complies with coding standards like gnu and gcc, and maybe even others like misra etc.

Georg-Johann




reply via email to

[Prev in Thread] Current Thread [Next in Thread]