[linux-dvb] [patch 3/3] fix strict aliasing warning.
js at linuxtv.org
Thu Sep 29 17:56:41 CEST 2005
On Thu, Sep 29, 2005 Ludwig Nussel wrote:
> Johannes Stezenbach wrote:
> > Ludwig Nussel wrote:
> > > Johannes Stezenbach wrote:
> > > > On Thu, Sep 29, 2005 Ludwig Nussel wrote:
> > > > > An int* must not be used to change some enum. As workaround a char* can be
> > > > > used.
> > > >
> > > > Says who?
> > >
> > > My local gcc guru ;-) As far as I understood gcc makes the
> > > assumption that a pointer to e.g. int never points to a float, enum
> > > something etc and vice versa. With that assumption it can optimize
> > > some cases better but may also produces garbage if your pointers do
> > > point to the same location. Only char* may point to anything.
> > gcc info pages contain some info in the -fstrict-aliasing
> > description (and of course the iso c99 spec).
> > But AFAIK enums have int type (unless you use -fshort-enum), and a
> > pointer to int may alias a pointer to enum without breaking the rules.
> I don't know.
I searched the c99 spec (WG14/N843), a few relevant quotes:
126.96.36.199 Enumeration specifiers
4 Each enumerated type shall be compatible with an integer type. The
choice of type is implementation-defined,97) but shall be capable of
representing the values of all the
7 An object shall have its stored value accessed only by an lvalue
expression that has one of the following types:61)
-- a type compatible with the effective type of the object,
61) The intent of this list is to specify those circumstances in which
an object may or may not be aliased.
Seems pretty clear to me: enums are compatible to int, and compatible
types may alias.
More information about the linux-dvb