From f25a506f918f4504dadcd393e407daa9304bda27 Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Mon, 13 May 2024 19:30:47 +0800 Subject: [PATCH] include: When defining NDEBUG, assert will implement alignment standards As defined by the C standard, if NDEBUG is defined, assert should do nothing but be simply defined as: #define assert(ignore) ((void)0) Reference link: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/assert.h.html Signed-off-by: yinshengkai --- include/assert.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/include/assert.h b/include/assert.h index 45d6e4d3230..f80b657840c 100644 --- a/include/assert.h +++ b/include/assert.h @@ -113,18 +113,26 @@ /* The C standard states that if NDEBUG is defined, assert will do nothing. * Users can define and undefine NDEBUG as they see fit to choose when assert * does something or does not do anything. + * + * #define assert(ignore) ((void)0) + * + * Reference link: + * https://pubs.opengroup.org/onlinepubs/009695399/basedefs/assert.h.html + * + * ASSERT/VERIFY is a non-standard interface, implemented using internal + * */ #ifdef NDEBUG -# define assert(f) ((void)(1 || (f))) -# define VERIFY(f) assert(f) +# define assert(f) ((void)0) +# define ASSERT(f) ((void)(1 || (f))) +# define VERIFY(f) ((void)(1 || (f))) #else # define assert(f) _ASSERT(f, __ASSERT_FILE__, __ASSERT_LINE__) +# define ASSERT(f) _ASSERT(f, __ASSERT_FILE__, __ASSERT_LINE__) # define VERIFY(f) _VERIFY(f, __ASSERT_FILE__, __ASSERT_LINE__) #endif -#define ASSERT(f) assert(f) - /* Suppress 3rd party library redefine _assert/__assert */ #define _assert _assert