Is the definition of “volatile” this volatile, or is GCC having some standard compliancy problems?
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 accessed again after that. Seems like a perfect candidate for volatile. But I'm having some problems actually getting this to work with GCC. Here is an example function: void volatileZeroMemory(volatile void* ptr, unsigned long long size) { volatile unsigned char* bytePtr = (volatile unsigned char*)ptr; while (size--) { *bytePtr++ = 0; } } Simple enough. But the code that GCC actually generates if you call it varies wildly