observability

Barry Margolin barmar at think.COM
Thu Sep 7 13:03:32 AEST 1989


In article <1989Sep6.183349.2866 at jarvis.csri.toronto.edu> flaps at dgp.toronto.edu (Alan J Rosenthal) writes:
>Many people claim that "volatile" is meaningless since it is not observable.

Here's a simple example where I think "volatile" is meaningful:

int global_variable;

handler() {
	global_variable = 2
}

main() {
	signal(SIGSOMETHING, handler);
	global_variable = 1;
	<expression that raises SIGSOMETHING>;
	printf("%d", global_variable);
}

I believe that it would be valid for an implementation to print either
1 or 2, because the lack of a "volatile" modifier permits
global_variable's value to be cached between the assignment and the
printf.  Adding a "volatile" modifier disallows this optimization, so
the program must print 2.

>bvs at light.uucp (Bakul Shah) writes:
>>Is a program with *no* output of any kind observable?

This reminds me of the old stories about an optimizing Fortran
compiler that was doing amazingly well on benchmarks because it
optimized away the entire program because it had no I/O statements.

Barry Margolin
Thinking Machines Corp.

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



More information about the Comp.std.c mailing list