include: Safely discard the const qualifier using the discard_const macro

Andrew Talbot Andrew.Talbot at
Sat Oct 7 05:03:30 CDT 2006

Hans Leidekker wrote:

> An alternative would be to make the return value const.

The problem with that is that sometimes these functions are called with
writeable strings, and the return value is used to modify the original
string, something like:

    static WCHAR stringW = {'s','t','r','i','n','g','\\',0};
    WCHAR *p;

    p = strchrW(stringW, '\\');
    *p = {'\n'};

Another solution might be, where appropriate - such as in strchrW() - to
replace certain functions with versions that, instead of returning a
pointer, returns an offset from the start of the string using a signed
integer type, i.e., in this case, declared as something like:

    INT strchrofsW(const WCHAR *str, WCHAR ch);

This could return a negative value (such as -1) for the "not found" case,
since ch could be at offset zero.

I think that would work for const and non-const strings, alike.

-- Andy.

More information about the wine-devel mailing list