I have a buffer that I use for UART, which is declared this way:
union Eusart_Buff {
uint8_t b8[16];
uint16_t b9[16];
};
struct Eusart_Msg
The Standard lacks any means by which programmers can demand that operations that access a region of storage by means of an ordinary pointer are completed before a particular volatile
pointer access is performed, and also lacks any means of ensuring that operations which access a region of storage by means of an ordinary pointer are not carried out until after some particular volatile
pointer access is performed. Since the semantics of volatile
operations are Implementation-Defined, the authors of the Standard may have expected that compiler writers would recognize when their customers might need such semantics, and specify their behavior in a fashion consistent with those needs. Unfortunately, that hasn't happened.
Achieving the semantics you require will either making use of a "popular extension", such as the -fms-volatile
mode of clang, a compiler-specific intrinsic, or else replacing memcpy
with something that's so horribly inefficient as to swamp any supposed advantage compilers could gain by not supporting such semantics.