unary +, volatile

KW Heuer kwh at bentley.UUCP
Tue Apr 22 14:37:44 AEST 1986


In article <951 at dataioDataio.UUCP> dataioDataio!bright (Walter Bright) writes:
>In article <687 at bentley.UUCP> kwh at 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



More information about the Comp.lang.c mailing list