Daniel Berlin <[EMAIL PROTECTED]> writes:

| >> object volatile).
| >
| > I don't understand your point. given
| >     void Foo (char const * a) { *(char *)a = 5; }
| > the compiler generates code to store 5 through the pointer 'a'.  It doesn't 
turn
| > this into a call to 'abort', because it thinks you're writing to const 
storage.
| 
| Is this *always* the cast, or just in the example above?
| 
| >
| > So, here it appears the compiler does believe the (char *) cast.
| 
| I imagine this is due to some workaround in an optimizer for some bug
| it exposed elswhere.

I do not understand your sentence; could you clarify?

Given the above definition of Foo(), the following shall pass
assertion

        int main()
        {
               int char a = 30;
               Foo(&a);
               assert(a == 5); 
        }


| >  Why should it
| > not believe a (char volatile *) cast -- unless it can determine the static 
type
| > of the object pointed to?
| 
| It appears he was saying that *even if it could determine the static
| type*, the volatile qualifier on the cast *made the object not that
| type anymore*.


I think care needs to be exercise here about terminology, because it
appears that everybody has its own dialect that ultimately leads to
lot of confusion.  Let me give my answer based on the terminology 
in the C++ standard that I'll reprroduce below.

If you can determine that the *dynamic type* of an object is const,
and yet users writes to it, then you're well-founded to do whatever
you like.  Whoever, just using the static type without further
information that relates it to the dynamic type is insufficient.

Similarly, if you can determine that the dynamic type of an object is
volatile, yet uses access it through non volatile then you can
whatever you like with the program.

Notice that "dynamic type" talks about type of objects, whereas static
type talks about type of expression.
   

   1.3.3 dynamic type 
   the type of the most derived object (1.8) to which the lvalue
   denoted by an lvalue expression refers. [Example: if a pointer
   (8.3.1) p whose static type is pointer to class B is pointing to an
   object of class D, derived from B (clause 10), the dynamic type of
   the expression *p is D. References (8.3.2) are treated similarly. ] 
   The dynamic type of an rvalue expression is its static type.

   1.3.11 static type
   the type of an expression (3.9), which type results from analysis
   of the program without considering execution semantics. The static
   type of an expression depends only on the form of the program in
   which the expression appears, and does not change while the program
   is executing. 

Reply via email to