comctl32_tests: Janitorial: write-strings warning fix

Andrew Talbot Andrew.Talbot at talbotville.com
Sat May 27 14:37:47 CDT 2006


Hi Vitaliy,

I am having a go at the janitorial project of fixing certain compiler
warnings suggested at http://wiki.winehq.org/CompilerWarnings/.

When the -Wwrite-strings flag is set, code like this:

    char *a = "string";

produces the message "warning: assignment discards qualifiers from pointer
target type". Similarly, this:

    char *p = NULL;
    *p = "string";

produces the message "warning: initialization discards qualifiers from
pointer target type".

For internal simple string variables, the solution is to add the const
keywork:

   const char *a = "string";

However, with structS , because it seems unwise to change elements of type
char * to type const char *, I am changing the initializations or
assignments to satisfy the pre-existing type. Thus, I have used code like

    char s[] = "string";
    x.pszText = s;    

where x is the struct in question.

Because I have had at least one patch like this accepted, I assumed what I
was doing was OK. I guess another way of preventing this warning would be
to use:

    x.pszText = (LPSTR) "string";

Assuming there is no danger in using this method, then it is neater for a
single assignment. The array method may be better when the same text is
assigned several times in the same function or file.

If what I am doing is incorrect or not helpful, I would welcome advice to
that effect. After all, I'm trying to make myself useful, not mess things
up.

Thanks,

-- Andy.





More information about the wine-devel mailing list