user32: Remove unneeded casts.

Alexandre Julliard julliard at winehq.org
Sat Dec 29 03:46:16 CST 2007


Andrew Talbot <Andrew.Talbot at talbotville.com> writes:

> In general, I have left the casts in where one PVOID-type handle was cast as
> another, e.g. HMODULE as HANDLE: I wasn't sure if strict typing might (one
> day) be an issue. AFAIK, my only transgressions were when I removed the
> casts from the return values of some {Local|Global}Alloc() and family
> functions, where they, strictly speaking, return a handle, not a literal
> PVOID, so arguably should be cast. For example:
>
>     PSID pSid = (PSID)LocalAlloc(0, cBytes);
>
> Since LocalAlloc() returns a HLOCAL - which just happens to be a PVOID - one
> might argue that the cast should remain. As another example of
> type-equivalence versus -distinction, DWORD and ULONG are both defined as
> unsigned long, but I have currently left them as distinct types, too.
>
> I would be glad for feedback on how type-strict we should be, please.

We want to be as type-strict as possible, but that doesn't mean we want
explicit typecasts, just the opposite in fact. The only way to benefit
from type strictness is to not use casts and let the compiler warn about
mismatches. That's also why generic handles like HANDLE or HLOCAL are
defined as void*, so that they can be assigned to other types without
casting. So typecasts of generic handle types, or of integer types,
should all be avoided as far as possible.

-- 
Alexandre Julliard
julliard at winehq.org



More information about the wine-devel mailing list