rbbb@rice.EDU (David Chase) (04/27/87)
How does one make the distinction (in C, as proposed by ANSI) between "a volatile pointer to something" and "a pointer to volatile something"? An example of a pointer to a volatile is the address of a memory-mapped device register; an example of a volatile pointer is an extern referenced in a signal handler. I imagine it is also possible to have a volatile pointer to a volatile something, but I can't think of any worthwhile examples. David
karl@haddock.UUCP (04/28/87)
In article <7124@brl-adm.ARPA> rbbb@rice.EDU (David Chase) writes: >How does one make the distinction (in C, as proposed by ANSI) between "a >volatile pointer to something" and "a pointer to volatile something"? An >example of a pointer to a volatile is the address of a memory-mapped >device register; an example of a volatile pointer is an extern referenced >in a signal handler. I believe the former is "something * volatile foo" whereas the latter is "volatile something * foo". The same syntactic distinction is made for the "const" attribute. I think it looks ugly and confusing. (But I used to have trouble with prefix/postfix ++ when I was learning C, and I got that straight; maybe this is no worse.) In a program I wrote yesterday, I needed a pointer to a volatile pointer to char. (The pointer resided in shared memory, its referent did not.) This would seem to require "char * volatile * foo". I think "typedef char *str; volatile str * foo" should have worked too, but the compiler didn't like it. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
ftw@datacube.UUCP (04/29/87)
I believe the following should work: volatile char *ptr_to_volatile; /* variable pointer to a volatile char */ char *volatile volatile_ptr; /* volatile pointer to a variable char */ The former tells the compiler not to do anything silly (optimize) with the object pointed at, and the latter instructs the compiler to not optimize any usage of the pointer. This also is applicable to the "const" keyword; the above code example is my paraphrasing of the October '86 draft standard. Farrell Woods, Datacube, Inc.
mouse@mcgill-vision.UUCP (05/07/87)
In article <7124@brl-adm.ARPA>, rbbb@rice.EDU (David Chase) writes: > How does one make the distinction (in C, as proposed by ANSI) between > "a volatile pointer to something" and "a pointer to volatile > something"? Someone posted something about "char * volatile foo". Somehow I would prefer (volatile char) *foo; and volatile (char *) foo; Would these be legal? Would they have the desired effects? der Mouse (mouse@mcgill-vision.uucp)