Consider the following code:
volatile uint32_t word;
for (i=0; i<10; i++)
{
word = *(uint32_t *)(ADDRESS_IN_MEMORY);
printf("%"PRIu32, word);
some_function_compiled_in_other_object(); /* this function may or may not change memory content at adress ADDRESS_IN_MEMORY */
}
So, since word
is volatile, we know that word = *(uint32_t *)(ADDRESS_IN_MEMORY)
will be indeed executed 10 times. But, is there any promise regarding the system cache here? I would expect that the compiled code will invalidate ADDRESS_IN_MEMORY
before\after each read from this address, so that word
will be loaded with the value from system memory and not the cache. Is that promised?
Does the answer depends on whether or not compiler knows about some_function_compiled_in_other_object
changing value at memory address ADDRESS_IN_MEMORY
?