Hi,

I'm using sdcc-stm8 with following code:

struct FLASH_t { ... ; volatile uint8_t iapsr; ...};
#define FLASH ((struct FLASH_t *)BASE_ADDRESS_OF_FLASH_CONTROLLER)

Program waits end of flash operation in a busy loop:

while ((FLASH->iapsr & 5) == 0) ...;

it works well rereading value of iapsr in every check. But in following structure:

uint8_t r= FLASH->iapsr;
while ((r & 5) == 0)
  r= FLASH->iapsr;

iapsr is read just once and the cycle uses that value without rereading the register. Even the following code uses the value which has been read before the cycle:

uint8_t r= FLASH->iapsr & 5;
while ((FLASH->iapsr & 5) == 0) ...

It looks that "volatile"-ness of a struct member disappears in some situations. Is it OK in C, or is it a bug?

Daniel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to