This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 6bdd71565ad include/assert.h: Define assert again at each inclusion.
6bdd71565ad is described below
commit 6bdd71565ad4d0095b73f09ab81c4f570b2aeec5
Author: Marco Casaroli <[email protected]>
AuthorDate: Sat Oct 17 19:51:39 2026 +0200
include/assert.h: Define assert again at each inclusion.
C11 7.2 says that a program can include <assert.h> more than once.
Each inclusion defines assert again according to the current state
of NDEBUG. The include guard of assert.h covered the whole file, so
a second inclusion did nothing. After "#undef assert" and a second
inclusion, assert was not defined. A change of NDEBUG between two
inclusions also had no effect.
Move the definition of assert after the include guard, as other C
libraries do. The rest of the header stays inside the guard.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
include/assert.h | 39 +++++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/include/assert.h b/include/assert.h
index cac7cb3a241..5d41ea85844 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -103,22 +103,6 @@
# define DEBUGVERIFY(f) ((void)(f))
#endif
-/* 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
- */
-
-#ifdef NDEBUG
-# define assert(f) ((void)0)
-#else
-# define assert(f) _ASSERT(f, __ASSERT_FILE__, __ASSERT_LINE__)
-#endif
-
/* ASSERT/VERIFY are NuttX-specific APIs.
* They are always enabled, regardless of NDEBUG/CONFIG_DEBUG_ASSERTIONS.
* The argument is evaluated exactly once.
@@ -204,3 +188,26 @@ void __assert(FAR const char *filename, int linenum,
#endif /* __ASSEMBLY__ */
#endif /* __INCLUDE_ASSERT_H */
+
+/* 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)
+ *
+ * The header may be included more than once, and each inclusion defines
+ * assert again according to the current state of NDEBUG. So this part is
+ * outside of the include guard.
+ *
+ * Reference link:
+ * https://pubs.opengroup.org/onlinepubs/009695399/basedefs/assert.h.html
+ */
+
+#ifndef __ASSEMBLY__
+# undef assert
+# ifdef NDEBUG
+# define assert(f) ((void)0)
+# else
+# define assert(f) _ASSERT(f, __ASSERT_FILE__, __ASSERT_LINE__)
+# endif
+#endif