Volatile global variable compiler warning
Posted on 2010-08-20
I have two threads that share a global array variable. To be thorough and to not get caught by compiler optimizations, I declared the array as volatile. This also happens with a single thread.
When I reference the pointer to the array in a function, I get the compiler warning listed below (Visual studio 2005 C compiler)
warning C4090: 'function' : different 'volatile' qualifiers
Why would the fact that's it's a volatile global cause a problem? What am I doing wrong? ( I looked at the MSDN article but that didn't help)
volatile uint8_t g_my_array;
memset(g_my_array, 0, sizeof(g_my_array)); //this causes the warning
I can cast the first argument as (void*) and get rid of the warning, but that just feels wrong.
What's the right way to do this?