Subject: Re: toolchain/22118: make won't compile with -Wcast-qual -Wstrict-prototypes and more
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Greg A. Woods <woods@weird.com>
List: tech-toolchain
Date: 07/12/2003 05:17:38
[ On Saturday, July 12, 2003 at 01:40:14 (-0400), der Mouse wrote: ]
> Subject: Re: toolchain/22118: make won't compile with -Wcast-qual -Wstrict-prototypes and more
>
> Well, the const qualifier is not really on the storage area in the
> cases in question; it's on the pointed-to type of a pointer.

I'm sure you know what I'm about to say but I'm just trying to be
pedantic since when you get specific about the cases you say are in
question the same rules still apply.  If you qualify a storage area as
"const" then you cannot pass it to any function which does not promise
to leave it unchanged.

The way "const type *" or "const type[]" is used is most definitely
intended to apply to the storage the pointer points to, not the storage
of the pointer variable itself.

I.e. if you want to use strict "const" qualifiers on your data
definitions then you must use separately defined storage areas for
separate function calls when one of those calls declares that it will
modify the storage and the other declares that it will not.

Yes, obviously strict use of "const" qualifiers complicates many things
and causes many inefficiencies, but the only _portable_ alternatives are
either to not be so strict in declaring the qualifiers for various
function parameters, and/or not be so strict in declaring "const"
qualifiers for storage passed to those functions.

> > [...], but the only portable alternative is to qualify the parameter
> > as const (and hope it really won't be modified! ;-).
> 
> What parameter?

The parameter (or return value) which the compiler is complaining causes
the 'const' qualifier to be discarded, of course.  (thus the reaons some
folks call it "const poisoning" :-)

-- 
								Greg A. Woods

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