Subject: Re: toolchain/22118: make won't compile with -Wcast-qual
To: None <Richard.Earnshaw@arm.com>
From: Greg A. Woods <woods@weird.com>
List: tech-toolchain
Date: 07/16/2003 14:44:42
[ On Wednesday, July 16, 2003 at 11:30:24 (+0100), Richard Earnshaw wrote: ]
> Subject: Re: toolchain/22118: make won't compile with -Wcast-qual   -Wstrict-prototypes and more
>
> It is not pointer aliasing.  Read the standard (specifically section 6.3). 
>  foo and const foo are in the same alias set (one is a qualified version 
> of the other).

I beg to differ, though I can't read the standard and both K&R 2nd
edition as well as Harbison & Steele 4th edition are quite careful to
avoid use of the phrase "pointer aliasing".

Certainly the deconst() that der Mouse proposed is absolutely an example
of pointer aliasing as I understand it, as would be any hacks with unions.

K&R 2nd edition states quite emphatically on p. 103:

    The valid pointer operations are assignment of pointer of the same
    type, adding or subtracting a pointer and an integer, subtracting or
    comparing two pointers to members of the same array, and assigning
    or comparing to zero.  All other pointer aritmetic is illegal.

Assigning a "const char *" variable to a "char *" variable requires a
cast, but of course that cast discards the 'const' qualifier and thus
the warning from '-Wconst-qual'.

-- 
						Greg A. Woods

+1 416 218-0098                  VE3TCP            RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>          Secrets of the Weird <woods@weird.com>