[net.lang.c] unary +, volatile

kwh@bentley.UUCP (KW Heuer) (04/22/86)

In article <951@dataioDataio.UUCP> dataioDataio!bright (Walter Bright) writes:
>In article <687@bentley.UUCP> kwh@bentley.UUCP (KW Heuer) writes:
>>[3]  Someone proposed using "a+(volatile)(b+c)".  I think this is workable,
>>though not quite the same meaning as volatile applied to a simple variable.
>
>Not even close! ... It makes about as much intuitive sense as "a+(while)(b+c)"

The similarity is that both forms of volatile would mean "don't optimize".

>'volatile' means to the compiler:
>	o The value of the variable can change anytime (asynchronously),
>	  and the value can be read anytime (asynchronously) independently
>	  of the executing program (such as an I/O port register).

Is it really independent of the *program*, or just the current function?  I.e.
is it appropriate to write
	volatile int caught;
	void catch() { caught = 1; }
	main() {
		signal(SIGINT, catch);
		caught = 0;
		...
		if (caught) ...
	}
to tell the compiler that "caught" might change asynchronously?  (I believe
the current compilers must assume this for all external variables, which cuts
down on the amount of optimization that can be performed.)

Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint