From ad12cc089cc648f0b53ff457df17c44e7cbc4ffc Mon Sep 17 00:00:00 2001 From: Jake Stine Date: Wed, 25 Nov 2020 10:16:19 -0800 Subject: [PATCH] Improved code quality of retro_assert macro Macros without do{}while() wrapping behave more like regular C expressions. The macro can now be nested/embedded inside of other similar compound statements and conditionals without introducing syntax errors. This change has no risk of negatively impacting existing code. --- libretro-common/include/retro_assert.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libretro-common/include/retro_assert.h b/libretro-common/include/retro_assert.h index 090e9f101c..79dbb32e06 100644 --- a/libretro-common/include/retro_assert.h +++ b/libretro-common/include/retro_assert.h @@ -27,9 +27,7 @@ #ifdef RARCH_INTERNAL #include -#define retro_assert(cond) do { \ - if (!(cond)) { printf("Assertion failed at %s:%d.\n", __FILE__, __LINE__); abort(); } \ -} while(0) +#define retro_assert(cond) ((void)( (cond) || (printf("Assertion failed at %s:%d.\n", __FILE__, __LINE__), abort(), 0) )) #else #define retro_assert(cond) assert(cond) #endif