volatile required?

Barry Margolin barmar at kulla
Fri Sep 29 02:33:46 AEST 1989


In article <712 at Aragorn.dde.dk> ct at dde.dk (Claus Tondering) writes:
>	  int p=3, *q=&p;
>	  *q=4;
>	  printf("%d\n",p);
>Is it acceptable that this program prints 3 instead of 4? The variable
>p is not declared volatile, and therefore the fact that *q=4 assigns
>4 to p may be considered a side effect.

No, the program must print 4.  Since p's address is taken, the
optimizer should know that it isn't safe to assume that only
assignments to p will modify its value.

Barry Margolin, Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.std.c mailing list