On 1/3/2024 10:11 AM, Fotis Panagiotopoulos wrote:
That would seem a little odd since there was a PR a few years ago to
change all instances of assert/ASSERT to DEBUGASSERT to save code size.

How is that so?

As I see here:
https://github.com/apache/nuttx/blob/master/include/assert.h#L122
assert defined exactly as DEBUGASSERT.

There shouldn't be any code size difference at all.

When CONFIG_DEBUG_ASSERTIONS is not defined, then all occurrences of DEBUGASSERT compile to nothing (actually the current version compiles to an expression that is optimized out):

   #undef DEBUGASSERT  /* Like ASSERT, but only if
   CONFIG_DEBUG_ASSERTIONS is defined */

   #ifdef CONFIG_DEBUG_ASSERTIONS
   #  define DEBUGASSERT(f) _ASSERT(f, __DEBUG_ASSERT_FILE__,
   __DEBUG_ASSERT_LINE__)
   #else
   #  define DEBUGASSERT(f) ((void)(1 || (f)))
   #endif

This value, ((void)(1 || (f))), is completely removed by the optimizer because of short-circuiting and dead code removal.  So the code is much smaller if CONFIG_DEBUG_ASSERTIONS is not enabled.  If DEBUGASSERT() is replaced with assert() than that code bloat would be unconditional, although somewhat less than when assertions are enabled.

This same kind of logic also applies to  DEBUGPANIC and DEBUGVERIFY.

Xiao Xiang made that change to reduce the size as needed by their products.  He is the person you should be talking to.

Reply via email to