Re: `volatile' on local variable used outside of function



nickptar wrote:
/* begin example.c */
static int* ptr;

static void inner_fn(void)
{
        *ptr = 1;
}

void outer_fn(void)
{
        int i = 0;
        ptr = &i;
        inner_fn();
        printf("%d\n", i);
}
/* end example.c */

Do I then have to declare `i'
as `volatile' to get the expected behavior?

Any decent compiler should detect that you're using a pointer to this local variable. I don't think you need to declare it "volatile".

If I'm wrong, I'd like to see a reasonable explanation.
.



Relevant Pages