Wide-string Functions: Double Casting
Marcus Meissner
meissner at suse.de
Tue Aug 8 03:39:30 CDT 2006
On Mon, Aug 07, 2006 at 09:54:20PM +0100, Andrew Talbot wrote:
> Although I accept that my opinion may not be universally shared :-), I
> believe that it is better to turn -Wcast-qual on permanently and
> double-cast the appropriate return values of the relevant wide-string
> functions (strchrW(), strrchrW(), strpbrkW(), memchrW() and memrchrW())
> than to leave it normally turned off: that way, the developers can avoid
> violations as they go, and give the janitors a break ;-). These functions
> are ubiquitous and widely understood, and they account for the vast
> majority of cast-qual warnings.
>
> Because, as I understand it, we are aiming for C89 compatibility, and to try
> to maximise portability, I am proposing to use size_t, rather than
> uintptr_t (which is a C99 type): it seems like the next-best thing. So I
> would like to submit a patch that, for example, changes strchrW() to:
>
> extern inline WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
> {
> WCHAR *ret = NULL;
> do { if (*str == ch) ret = (WCHAR *)(size_t)str; } while (*str++);
> return ret;
> }
>
> What do people think? Should I just send in the patch and see what criticism
> it engenders? Does anyone have a system on which this would fail or
> generate other warnings in place of the cast-qual one?
>
> Needless to say, I hope to be tackling the cast-qual janitorial task, soon;
> hence, my sudden interest in this.
I asked our gcc gurus.
- If you want to cast, do not use size_t but uintptr_t.
Or:
- Do not inline the function, and compile its file without -Wcast-qual.
- Fix the prototype to read "extern inline const WCHAR *strrchrW( const WCHAR *str, WCHAR ch )"
Ciao, Marcus
More information about the wine-devel
mailing list