Re: Question on volatile functions and GCC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jeffrey Walton schrieb:
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)
    ;;
}

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

volatile can be used to express that a function is noreturn like in the following example where only one call of f() is issued:

typedef void ft (void);
volatile ft f;

void foo (void)
{
    f();
    f();
}

or this example that throws
<stdin>: In function 'f':
<stdin>:4:1: warning: 'noreturn' function does return [enabled by default]

typedef void ft (void);
volatile ft f;

void f (void) {}

In your example, the volatile looks meaningless and like a typo.

Johann



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux