Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "type punned" warnings



On Tue, Feb 28, 2006 at 11:51:52PM +0000, Peter Stephenson wrote:
> We've been getting these from gcc 3+ for a while.  I think Wayne
> suggested some casts to void * would be enough to remove them.

Yeah, that was a pretty ugly kluge of dubious usefulness.

I've created a patch that fixes the aliasing at a fundamental level.
It's really big, so I'll provide a link instead of attaching it:

    http://opencoder.net/punning.diff

There were two classes of warnings:

 1. Multiple structure pointers were being cast to a HashNode (struct
    hashnode *).

 2. A LinkList (struct linklist *) was being cast to a LinkNode (struct
    linknode *).

I fixed the first class of warnings by putting a "struct hashnode node;"
at the start of every structure that was getting cast to HashNode.  This
required sprinkling some "node." prefixes around the code for the three
affected structure variables (next, nam, and flags).

I fixed the second class of warnings by making a LinkList a union of a
"struct linklist list;" and a "struct linknode node;".  This tells the
compiler that the type punning between the two pointer classes needs to
be taken into account when optimizing.  This required sprinkling some
"list." prefixes around the code and referring to the "node" when
appropriate.  I also added an "int flag" to the linklist structure,
since it now fits in the union (which an uncommitted patch of mine will
like having around).

I also think that it would be nice to rename the "last" variable in the
LinkNode structure to be "prev", which is a clearer name to me.  I
didn't do that (at least, not yet) because it would just clutter up an
already huge patch.

..wayne..



Messages sorted by: Reverse Date, Date, Thread, Author