This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: volatile semantics
- From: Daniel Berlin <dberlin at dberlin dot org>
- To: "D. Hugh Redelmeier" <hugh at mimosa dot com>
- Cc: gcc at gcc dot gnu dot org, Nathan Sidwell <nathan at codesourcery dot com>, Dale Johannesen <dalej at apple dot com>, Mike Stump <mrs at apple dot com>
- Date: Sat, 16 Jul 2005 12:56:36 -0400
- Subject: Re: volatile semantics
- References: <851D2CB0-93DF-4C49-A6A8-8895DB1A08F9@apple.com> <42778D99.7070904@codesourcery.com> <b0f8ff9938df57bbfda0ec3aea4fc02b@apple.com> <Pine.LNX.4.61.0507161250120.1478@redshift.mimosa.com>
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.