casaroli opened a new pull request, #20731:
URL: https://github.com/apache/nuttx/pull/20731

   ## Summary
   
   C11 7.2 says that a program can include `<assert.h>` more than once, and 
that each inclusion defines `assert` again according to the current state of 
`NDEBUG`. The include guard of NuttX's `assert.h` covered the whole file, so a 
second inclusion did nothing: after `#undef assert` and a second `#include 
<assert.h>`, `assert` was not defined, and a change of `NDEBUG` between two 
inclusions had no effect.
   
   This PR moves the definition of `assert` after the include guard (with 
`#undef assert` first), as other C libraries do. The rest of the header 
(`ASSERT`, `DEBUGASSERT`, ...) stays inside the guard.
   
   ## Impact
   
   Only a second inclusion of `<assert.h>` behaves differently: it now defines 
`assert` again. A single inclusion is unchanged.
   
   ## Testing
   
   A test program that includes `<assert.h>`, does `#undef assert`, includes it 
again and uses `assert()`, and switches `NDEBUG` between two inclusions: on 
master it does not compile (implicit declaration of `assert`); with this PR it 
compiles and passes on `qemu-armv8a:knsh` (QEMU 11 with HVF on an Apple M4).
   
   `ostest` on `qemu-armv8a:knsh` and `qemu-armv8a:nsh` ends with `ostest_main: 
Exiting with status 0`. `lm3s6965-ek:qemu-flat` builds. `tools/checkpatch.sh -c 
-u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to