[Top][All Lists]

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

Re: [avr-gcc-list] Tip: handling volatile operands

From: Paulo Marques
Subject: Re: [avr-gcc-list] Tip: handling volatile operands
Date: Fri, 11 Jan 2008 18:18:45 +0000
User-agent: Thunderbird (X11/20070509)

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."

reply via email to

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