Union an alias when the difference is the volatile qualifier?
Jeffrey Walton
noloader@gmail.com
Mon Aug 3 17:32:00 GMT 2015
>> Does GCC consider an 'int' and a 'volatile int' (or 'int*' and a
>> 'volatile int*') almost the same?
>
> It's not symmetrical.
>
> The rules are the rules of the C standard. I don't think there's any
> intention to use GCC-specific rules....
Yes, correct.
> ...
> If an attempt is made to refer to an object defined with a
> volatile-qualified type through use of an lvalue with
> non-volatile-qualified type, the behavior is undefined.
>>>
>
> It's OK to cast a pointer to int to a pointer to volatile int and then
> dereference that pointer, but not vice versa. So, GCC must assume
> that a pointer to volatile int may point to a non-volatile int object.
> But the reverse is not true: GCC need not assume that a pointer to int
> may point to a volatile int.
One last question, and then I will be done. Is it OK to do in C++03 and above.
Sorry to ask. I have a heck of a time locating the relevant parts and
then parsing the standard _correctly_ at times (emphasis on
correctly).
Jeff
More information about the Gcc-help
mailing list