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 <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2024-05-13 19:30:47 +08:00 committed by Alan Carvalho de Assis
parent 72c1f779d1
commit f25a506f91

View file

@ -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