Help with understanding strict aliasing rules

Martin Lucina
Mon Aug 28 11:10:00 GMT 2006 said:
> Please read the actual standard too.  The rules about pointer type
> conversions are at  The appropriate paragraphs are paragraphs
> 1 and 7.

So according to paragraph 1, the following is legal (obviously, this is
basic C):

void *return_item (int *rc);

item_t *item_p;
int rc;

item_p = return_item (&rc);

but the case 

int return_item (void **item_p);

item_t *item_p;
int rc;

rc = return_item ((void **)&item_p);

is not legal since (void **) doesn't fall under the specification of
paragraph 1, but will work fine as long as item_p is only ever
dereferenced as an item_t?

In other words, (void *) is convertible to any incomplete or object
type, but (void **) is not, despite the fact that *(void **) is a (void

> (unless you cast it back to its original type first).  This warning
> should be interpreted as saying that your interfaces are badly designed,
> and the correct way to avoid the warning is to redesign them in a way
> where you do not need to cast between conflicting types.  (Even if you

Unfortunately I can't change the interfaces since they're used by
legacy code.  I'd just like to get rid of the warnings since if people
get used to ignoring the warnings in this code then they are likely to
miss other more important problems.


More information about the Gcc-help mailing list