Re: cast lvalues optimizing and strict-aliasing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Christian BRUEL <christian.bruel@xxxxxx> writes:

> thanks for your answer, this is what I fearing. However, I'm surprised
> when you say that the struct value as is accessed as a short, despite
> the char * cast: (from 9899:1999 6.5.4 "Preceding an expression by a
> parenthesized type name converts the value of the expresion to the
> named type").

The cast converts the value of the pointer.  It does not convert the
value which the pointer is pointing to.


> Now you seem to imply that the aliasing rule only looks at the final
> points-to object's effective type, not the expression's lvalue type
> implied by the cast or the temporary pointer.

C99 section 6.5 paragraph 7:

    An object shall have its stored value accessed only by an lvalue
    expression that has one of the following types:
    -- a type compatible with the effective type of the object,
    -- a qualified version of a type compatible with the effective type
       of the object,
    -- a type that is the signed or unsigned type corresponding to the
       effective type of the object,
    -- a type that is the signed or unsigned type corresponding to a
       qualified version of the effective type of the object,
    -- an aggregate or union type that includes one of the
       aforementioned types among its members (including, recursively, a
       member of a subaggregate or contained union), or
    -- a character type.

As you can see, the standard is written in terms of the type of the
object and the type of the expression which is used to access it.  The
type of any temporary pointer is irrelevant.

Ian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux