Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] Re: Code optimization problem

2005-01-25 by Robert Adsett

At 05:40 PM 1/25/05 +0000, you wrote:
>Robert,
>       Can you elaborate on how this is used?  Right now the statement:
>
>dummy = U0IIR;  // clear the flag
>
>Is optimized out in my UART ISR.


Given:

extern volatile char U0IIR;

char dummy;

where dummy is never referred to, then the lines

dummy = U0IIR;
U0IIR;
(void)U0IIR;

Should all produce similar code.  The last two should produce identical 
code.  With low optimization the first line might produce code that 
actually stores a value in dummy.

The last two lines are legal C and basically say read this value and ignore 
it.  The void cast on the last line tells compilers and static analysis 
tools that that is what you intended to do and that it's not a typo.

At no level of optimization should the read be optimized out for any of the 
above lines.  The volatile qualifier should prevent that kind of optimization.

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,
be they legal, genetic, or physical.  If you don't believe me, try to
chew a radio signal. "

                         Kelvin Throop, III

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.