shell32: Write-strings warning fix

Andrew Talbot Andrew.Talbot at
Wed Jun 7 15:31:50 CDT 2006

Robert Shearman wrote:
> Sorry, this is wrong. If InsertMenuItemA writes to the string then it
> will be corrupted and will display the wrong thing for further uses in
> the process.

A MENUITEMINFOA's dwTypeData is currently declared as writeable (LPSTR);
what it is initialised from will not affect that, but initialising it from
a non-const array does prevent a write-strings warning. So, assuming that
one eventual aim is to add -Wwrite-strings and -Wcast-qual to the make
flags, string variables that can be constified should be, and ones that
cannot (for example, because they must conform to the SDK) need to be
initialised from non-const sources, to reduce compiler noise. I consider
this variable to be constrained to remain writeable by compatibility
issues; otherwise, the best solution would be to declare it to be of type

> It is therefore better to cast it from a "const char *" 
> into a "char *"

A statement like

    char *s = (char *) "string";

would raise a cast-qual warning, when that flag gets turned on.

>  or to make it a non-static array at the top of the
> function.

My assumption, in declaring such a string-variable static, is that, for
functions that get called repeatedly, microseconds will be saved on the
second and each subsequent invocation, since the local variable will not
suffer repeated assignments of an invariant value. (Big deal? Maybe, but
harmless.) However, I think it is irrelevant to the issue in hand.

-- Andy.

More information about the wine-devel mailing list