Dave N6NZ wrote:

Dave Hansen wrote:

   switch (ioport)
   {
    case 1: ...
    case 2: ...
    case 99: ...
   }

This is (IMHO) a closer abstraction of what you actually want done.

But there is no general guarantee that the compiler won't turn a switch into an if..then..else if... chain. It would be an interesting test of the volatile keyword to see if declaring the switch variable volatile has the effect of forcing a jump table.

No, the compiler can not issue more reads for volatile values than the code asks for. That would lead to all sorts of nasty bugs, because reading a hardware register can have side effects the compiler doesn't know about (not to mention that the value can change while the "if..else if" is being evaluated).

If the compiler turns the switch into an "if..else if" construct, it must store the value in a temporary register and use that temporary value in the "if..else if" construct.

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

"God is real, unless declared integer."


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

Reply via email to