On Sat, 2005-07-16 at 12:50 -0400, D. Hugh Redelmeier wrote: > Sorry for the very late response. It is actually triggered by the > bugzilla entry > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22278 > > The motivating example, abstracted from a misbehaving part of X, is: > void test (char *addr) { > *((volatile char *) addr); > } > In this case, the fetch ("access") is required for the hardware to > behave. > ...
> 6.5.3.2: applying `*' to a pointer of type `T *' which points to an > object yields an lvalue of type `T' designating that object. So the > lvalue in the assignment has a volatile-qualified type. > > 6.3.2.1: when an object is said to have a particular type, the type is > specified by the lvalue used to designate the object. So the lvalue > having a volatile-qualified type *means* that the object it designates has > a volatile-qualified type; "has type X" and "is designated by an lvalue of How does this reasoning not apply to *((char *)a) = 5 where a was originally of a const qualified type? Or do you think you can only *add* qualifiers, and not remove them? Because if you allow casting away, then you can't ever trust const to be true either, just like we apparently can't trust the user saying "this is not volatile" (which they are doing by not declaring the original object volatile). There is no point in type qualifiers if they can be simply changed at will. Do not lie about your objects, and you will not be screwed over.