[Top][All Lists]

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

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

From: Weddington, Eric
Subject: RE: [avr-gcc-list] Re: C vs. assembly performance
Date: Sat, 28 Feb 2009 19:24:38 -0700


> -----Original Message-----
> From: 
> address@hidden 
> [mailto:address@hidden
> org] On Behalf Of Vincent Trouilliez
> Sent: Saturday, February 28, 2009 7:20 PM
> To: address@hidden
> Subject: Re: [avr-gcc-list] Re: C vs. assembly performance
> 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 wouldn't need *nested* ifs, but an if-else-if structure, or better yet, a 
table of function pointers, also known as a dispatch table. Each method depends 
on the type of data that you're switching on.

reply via email to

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