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 11:55 PM 1/24/05 +0000, you wrote:
>      I don't follow, the registers are declared thusly:
>
>#define SPI_SPDR   (*((volatile unsigned char *) 0xE0020008))


Sigh, It would probably help if I wrote what I was thinking.  I meant 
volatile when I wrote void.

Given the above, then the following line

  (void)SPI_SPDR;

should generate a read of the register (and discard the result) regardless 
of the level of optimization.  volatile tells the compiler that it must 
generate an access and not optimize it out.  If it does not then compiler 
has a bug.  You should probably write a short 2 or 3 line program to 
demonstrate it and report it.

Of course optimizers are notoriously buggy so turning down the optimization 
level to get correct code is not terribly unusual.  I seem to recall an 
instance or two where a minimum optimization was required in order to 
generate correct code but that's rather less common.

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.