Question on volatile functions and GCC

Jonathan Wakely jwakely.gcc@gmail.com
Mon Mar 4 23:46:00 GMT 2013


On 4 March 2013 23:40, Jeffrey Walton wrote:
> Hi All,
>
> I was looking at some slides on OpenSSL and secure memory wiping using
> volatile (Slide 36 at
> http://www.slideshare.net/guanzhi/crypto-with-openssl).
>
> I believe GCC's interpretation of the use for 'volatile' is memory
> mapped hardware. I think Ian stated it for me some time ago when I was
> trying to understand different interpretations among compilers. If
> volatile is for memory mapped hardware, why does GCC compile the
> following:
>
> volatile void clean_memory(volatile void* dest, size_t len)
> {
>   volatile unsigned char* p;
>   for(p = (volatile unsigned char*)dest; len; dest[--len] = 0)
>     ;;
> }

This doesn't compile, it dereferences void.  Did you mean p[--len] ?

> How does a function become a 'volatile' memory mapped object related
> to hardware?

The function isn't volatile, the return type is. Qualifying void as
volatile is meaningless, but allowed by the C grammar.



More information about the Gcc-help mailing list