I need a function that (like SecureZeroMemory from the WinAPI) always zeros memory and doesn\'t get optimized away, even if the compiler thinks the memory is never going to
I need a function that (like SecureZeroMemory from the WinAPI) always zeros memory and doesn't get optimized away,
This is what the standard function memset_s is for.
As to whether this behavior with volatile is conforming or not, that's a bit hard to say, and volatile has been said to have long been plagued with bugs.
One issue is that the specs say that "Accesses to volatile objects are evaluated strictly according to the rules of the abstract machine." But that only refers to 'volatile objects', not accessing a non-volatile object via a pointer that has had volatile added. So apparently if a compiler can tell that you're not really accessing a volatile object then it's not required to treat the object as volatile after all.