WINECFG: Eliminate some gcc 4.1 warnings caused by casts in
macros.
Francois Gouget
fgouget at free.fr
Fri Mar 3 08:29:43 CST 2006
On Fri, 3 Mar 2006, Mike McCormack wrote:
[...]
> They would prefer that we use statement expressions, which are gcc specific,
> in our macros. Something like:
Thanks for the explanation.
Sure, having an #ifdef/#else/#endif for each macro is way too painful.
But what about the following:
+#ifndef WINE_CAST
+# if __GNUC__
+# define WINE_CAST(ctype, val) ({ctype r=(ctype)(val);r;})
+# else
+# define WINE_CAST(ctype, val) ((ctype)(val))
+# endif
+#endif
+
+ #define Header_SetImageList(hwnd,himl) \
- (HIMAGELIST)SNDMSGA((hwnd),HDM_SETIMAGELIST,0,(LPARAM)himl)
+ WINE_CAST(HIMAGELIST, SNDMSGA((hwnd),HDM_SETIMAGELIST,0,(LPARAM)himl))
+
This pre-processes to code that uses the statement expression on gcc
compilers and to the regular cast for others. So there should be no
warning in either case (I couldn't check with gcc 4.1 but this
preprocesses to the expected form). I also checked with gcc 2.95 and it
compiles fine and without warning there which should be enough backwards
compatibility for everyone (otherwise we can go further and check the
GCC version).
Of course in a real patch the WINE_CAST macro would be declared
somewhere in windef.h, and we'd still have to change all the macros that
cast a function result. But that seems quite feasible and not too ugly
and I would be willing to submit such a patch. We may also want to find
a better name. WINE_MACRO_CAST? WINE_MCAST? __MACRO_CAST? WINE_CAST_RESULT?
Should I send such a patch?
--
Francois Gouget <fgouget at free.fr> http://fgouget.free.fr/
In a world without fences who needs Gates?
More information about the wine-devel
mailing list