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/15/2003 03:41:29
[ On Monday, July 14, 2003 at 20:26:42 (-0400), der Mouse wrote: ]
> Subject: Re: toolchain/22118: make won't compile with -Wcast-qual -Wstrict-prototypes and more
>
> or (d) turn them off with DECONST().
Use of something like DECONST() can _NEVER_ be correct unless it is
_ONLY_ ever applied DIRECTLY to string constants (or equivalent
initializer values that the compiler might place in read-only storage
and which by default would be declared as being located in
const-qualified storage). Any time you've run into a situation where
you need to use such a construct in an assignment or on a parameter
value then something is gravely wrong somewhere.
If you don't want to use -fwritable-strings then it would make a LOT
more sense to directly use something GCC-specific, such as a trailing
'W' on the string constant, rather than to try to pretend that there's
some magic macro which can be used portably to make string constants
writable (because as yet there is no such thing). A macro could be used
to hide the magic, but hiding such magic in a macro would obfuscate the
magic of course, but it would do so to the point where its importance
would likely be lost on any future maintainer unaware of the original
programmer's intent. Even if you do make it a macro, calling it
"deconst" would be misleading. "nonconst" would be closer, but perhaps
just something like "writable_string" would be most clear.
> I consider this better, because it becomes possible to turn them off
> piecemeal, only where they need to be turned off, without having to
> pull the affected code into a separate file to be built with different
> flags.
However nothing like this can be done portably, at least not until, and
unless, the C standard is changed to allow for this to be done.
--
Greg A. Woods
+1 416 218-0098 VE3TCP RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com> Secrets of the Weird <woods@weird.com>