Re: `volatile' on local variable used outside of function
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Tue, 27 Dec 2005 17:47:20 +0000 (UTC)
In article <1135704237.460269.312410@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
nickptar <nickptar@xxxxxxxxx> wrote:
>Let's say I have a situation like this:
>/* 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 */
>in which a global pointer is set to point to a function-local variable
>and then written to in another function. Do I then have to declare `i'
>as `volatile' to get the expected behavior?
No.
Effectively, you only need volatile for variables that might
be changed by something outside the normal flow of control,
such as by a signal handler.
You do, though, need to #include <stdio.h> to get the expected behaviour.
And you will need a main() somewhere along the line.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
.
- References:
- `volatile' on local variable used outside of function
- From: nickptar
- `volatile' on local variable used outside of function
- Prev by Date: Re: confused about behaviour of scanf
- Next by Date: Re: `volatile' on local variable used outside of function
- Previous by thread: `volatile' on local variable used outside of function
- Next by thread: Re: `volatile' on local variable used outside of function
- Index(es):
Relevant Pages
|
|