Type modifiers in C

Walter Bright bright at dataioDataio.UUCP
Tue Oct 29 07:33:07 AEST 1985


In article <943 at lll-crg.ARpA> brooks at lll-crg.ARpA (Eugene D. Brooks III) writes:
>Could someone explain all the details of what you might do with for example
>the volatile type modifier.  For instance does
>
>volatile int foo;	/* Mean that the int foo is volatile. */
 YES.

>int * volatile bar;	/* Mean that bar is a non volatile pointer
>			to a volatile int. */
 NO. Bar is a volatile pointer to a non-volatile int.

>int * volatile cat();	/* Mean that cat returns a pointer to a volatile int*/
 NO. Cat() returns a volatile pointer to an int.

>volatile int cat();	/* What does this mean? */
 Cat() returns a volatile int.

>volatile int * dog;	/* Mean that dog is a volatile pointer to a
>			non-volatile int. */
 Dog is a pointer to a volatile int.

>volatile int * volatile fly;	/* Mean a volatile pointer to a volatile int.*/
 YES.

The purpose of the volatile modifier is so that an optimizing compiler
can be told which variables are not candidates for common subexpression
elimination, which ones cannot be put in registers, and which ones are not
candidates for redundant load/store removal. Having a function return
a volatile is not an error, but it doesn't mean much (unless the compiler
is able to deduce that the function call is redundant!).
	My understanding of volatile is that it is a modifier and binds very
tightly. Whether it is left or right associative is not clear.
Such as:

	char * volatile * s;

	<volatile pointer to><pointer to><char>
		-OR-
	<pointer to><volatile pointer to><char>
		??



More information about the Comp.lang.c mailing list