> Dale Johannesen writes:
>> Nathan Sidwell wrote:
>> Also, I wonder about the following example
>>
>> int const avail = <something>
>>
>> int main() {
>>  while (*(int *)&avail == Foo ())
>>    do_something();
>>  return 0;
>> }
>>
>> Seeing through the const-stripping cast is a useful optimization.
>
> It is? Why would somebody write that?

- It shouldn't mater, GCC should simply treat the outermost cast as the
  effective definition of the qualified access path and type of the object
  referenced within this context. Although it seems very reasonable that a
  cast or parameter specification which results in any qualification being
  dropped, minimally produces a warning, just in case the dropping of the
  qualifier wasn't intended, as simply dropping a const qualifier for
  example does not warrant that object referenced is actually physically
  writable; i.e. for example a static const object may literally be stored
  in ROM, just as array/string, or structure literals may be; just as
  correspondingly dropping an objects volatile qualifier no longer warrants
  that it's logical reference will result in a physically access.

>> A further pathelogical case would be,
>>
>> int main() {
>>  while (*(int *)(volatile int *)&avail)
>>    do_something ();
>>  return 0;
>> }
>>
>> What should this do, treat the volatile qualifier as sticky?
>
> IMO, no, but surely we don't have to worry about this one. Either way
> is standard conformant and the user's intent is far from clear, so whatever
> we do should be OK.

- As above, the object should likely be simply references as if an (int *),
  nothing more nothing less. With a warning that the const qualifier was
  dropped upon a cast to (volatile int *), and that volatile was dropped
  upon it's final cast to (int *).



Reply via email to