X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e08d449f2ecbf6daf58669a911da944e559dcf49..8e77fd8bca165aab9709649d79a7cbc6a172d4e1:/include/wx/cpp.h diff --git a/include/wx/cpp.h b/include/wx/cpp.h index 657b0673eb..9fed106a76 100644 --- a/include/wx/cpp.h +++ b/include/wx/cpp.h @@ -79,6 +79,28 @@ */ #define wxEMPTY_PARAMETER_VALUE /* Fake macro parameter value */ +/* + Helpers for defining macros that expand into a single statement. + + The standatd solution is to use "do { ... } while (0)" statement but MSVC + generates a C4127 "condition expression is constant" warning for it so we + use something which is just complicated enough to not be recognized as a + constant but still simple enough to be optimized away. + + Another solution would be to use __pragma() to temporarily disable C4127. + + Notice that wxASSERT_ARG_TYPE in wx/strvargarg.h relies on these macros + creating some kind of a loop because it uses "break". + */ +#ifdef __WATCOMC__ + #define wxFOR_ONCE(name) for(int name=0; name<1; name++) + #define wxSTATEMENT_MACRO_BEGIN wxFOR_ONCE(wxMAKE_UNIQUE_NAME(wxmacro)) { + #define wxSTATEMENT_MACRO_END } +#else + #define wxSTATEMENT_MACRO_BEGIN do { + #define wxSTATEMENT_MACRO_END } while ( (void)0, 0 ) +#endif + /* Define __WXFUNCTION__ which is like standard __FUNCTION__ but defined as NULL for the compilers which don't support the latter.