Volatile type in ANSI C

Michael Meissner gamma at rtp47.UUCP
Sat Apr 27 00:22:43 AEST 1985


Both flavors of volatile have their uses:

    1)	volatile int *p;	/* p is a non-volatile ptr to volatile mem */
		The compiler can optimize `p' into a register, or some such,
		but every access to the memory p points to cannot be optimized.

    2)	int * volatile q;	/* q is a volatile ptr to non-volatile mem */
		This is useful for things like multi-processor implementations,
		where q can be modified at any time (though obviously you might
		get strange results if q is not aligned correctly, and the other
		processor takes more than 1 memory cycle to update q).  Because
		q is volitle, it means that anything it points cannot be
		optimized, and probably it should read:
			volatile int * volatile q;
	
	Michael Meissner
	Data General Corporation
	...ihnp4!mcnc!rti-sel!rtp47



More information about the Comp.lang.c mailing list