Ian Lance Taylor wrote:
"Phil Endecott" <spam_from_gcc_help@xxxxxxxxxxxx> writes:
I know that in some circumstances gcc will generate read-modify-write
sequences to access memory locations, for example if I have a bitfield
struct. Is there a way in which I can tell it to only do (32-bit)
word writes to a region of memory, and to do read-modify-write
sequences instead of byte writes, even though the processor does have
byte write instructions?
Sure, this is what the volatile qualifier is for. If you always
access the memory through volatile qualified pointers, the compiler
will always access the memory precisely as you write in the program.
Hi Ian, thanks for replying.
Could you help me out with an example? Say I have a uint8_t* that I
want to write to:
uint8_t* ptr = ......;
*ptr = 123;
How do I change that so that it does a read/modify/write? Are you
saying that I can do something like
volatile uint32_t* ptr = .....;
uint8_t* ptr2 = ptr;
*ptr2 = 123;
with appropriate extra casts and 'volatile's, and it will do what I want?
Cheers,
Phil.