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

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

RE: [avr-gcc-list] Inconsisten behaviour of switch statement


From: Eric Weddington
Subject: RE: [avr-gcc-list] Inconsisten behaviour of switch statement
Date: Mon, 26 Mar 2007 12:12:14 -0600

 

> -----Original Message-----
> From: Dave Hansen [mailto:address@hidden 
> Sent: Monday, March 26, 2007 10:38 AM
> To: address@hidden; 
> address@hidden; address@hidden
> Subject: RE: [avr-gcc-list] Inconsisten behaviour of switch statement
> 
> From: Eric Weddington <address@hidden>
> 
> > > From: Schwichtenberg, Knut 
> [mailto:address@hidden
> [...]
> > > Eric, the point is not that I don't like the output, but the
> > > case to be
> > > selected should be deterministic. I always thought that a switch
> > > statement would lead to identical results if the input value is
> > > identical. This is currently not true. The table jump for 
> a volatile
> > > variable is identical to an if-then-else structure of a 
> non-volatile
> > > variable and the current if-then-else implementation for 
> a volatile
> > > variable can not be simulated by a table jump.
> >
> >This is one of many reasons why I personally don't like 
> switch statements 
> >in
> >embedded code. I still suggest coding your algorithm as a 
> dispatch table.
> >Give it a try.
> 
> I think Knut has a point.  At least, if I understand what's 
> going on.  Given 
> code like
> 
>    switch (var)
>    {
>  p    <etc.>
>    }
> 
> If var is volatile, it should be read only once, regarless of 
> the number of 
> cases.  

<snip>

> But he shouldn't _have_ to do that.  Bug in gcc?

Hmm.. point. Maybe a "missed optimization" type of bug. You could fill out a
GCC bug report. Feel free to put me on the CC list of the bug report so I
can track it.

Eric





reply via email to

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