Skip to content
ASSERT_OR_FATAL

ASSERT_OR_FATAL

Description

Expression-form fatal assertion. When cond is false, logs msg at the caller’s __func__ / __LINE__ at FATAL severity and aborts; otherwise evaluates to 0. Designed for use inside designated- initializer literals and comma expressions where the statement-style LOG_FATAL(...) (do { ... } while (0)) does not fit.

Args are evaluated as a normal C ternary: cond once; msg only on the failure path. The whole macro has type int, so it composes inside ternaries and comma chains without further casting.

Parameters

Name Direction Description
cond in Boolean condition that must hold.
msg in Constant Zstr (string literal preferred).

Success

Evaluates to 0 when cond is true.

Failure

LogWrite(...) then Abort(); never returns.

Usage example (Cross-references)

Usage examples (Cross-references)
    ///
    #define BudgetAllocatorInitAligned(buf_ptr, total_bytes, slot_size_bytes, alignment_value)                             \
        (ASSERT_OR_FATAL((buf_ptr) != NULL, "BudgetAllocatorInit: NULL buf"),                                              \
         ASSERT_OR_FATAL((total_bytes) > 0, "BudgetAllocatorInit: zero buf_bytes"),                                        \
         ASSERT_OR_FATAL((slot_size_bytes) > 0, "BudgetAllocatorInit: zero slot_size"),                                    \
    #define BudgetAllocatorInitAligned(buf_ptr, total_bytes, slot_size_bytes, alignment_value)                             \
        (ASSERT_OR_FATAL((buf_ptr) != NULL, "BudgetAllocatorInit: NULL buf"),                                              \
         ASSERT_OR_FATAL((total_bytes) > 0, "BudgetAllocatorInit: zero buf_bytes"),                                        \
         ASSERT_OR_FATAL((slot_size_bytes) > 0, "BudgetAllocatorInit: zero slot_size"),                                    \
         ASSERT_OR_FATAL(                                                                                                  \
        (ASSERT_OR_FATAL((buf_ptr) != NULL, "BudgetAllocatorInit: NULL buf"),                                              \
         ASSERT_OR_FATAL((total_bytes) > 0, "BudgetAllocatorInit: zero buf_bytes"),                                        \
         ASSERT_OR_FATAL((slot_size_bytes) > 0, "BudgetAllocatorInit: zero slot_size"),                                    \
         ASSERT_OR_FATAL(                                                                                                  \
             (alignment_value) >= sizeof(void *) && ((alignment_value) & ((alignment_value) - 1)) == 0,                    \
         ASSERT_OR_FATAL((total_bytes) > 0, "BudgetAllocatorInit: zero buf_bytes"),                                        \
         ASSERT_OR_FATAL((slot_size_bytes) > 0, "BudgetAllocatorInit: zero slot_size"),                                    \
         ASSERT_OR_FATAL(                                                                                                  \
             (alignment_value) >= sizeof(void *) && ((alignment_value) & ((alignment_value) - 1)) == 0,                    \
             "BudgetAllocatorInit: alignment must be a power of two >= sizeof(void *)"                                     \
             "BudgetAllocatorInit: alignment must be a power of two >= sizeof(void *)"                                     \
         ),                                                                                                                \
         ASSERT_OR_FATAL(                                                                                                  \
             (size)(total_bytes) >= (size)(ALIGN_UP_POW2((u64)(buf_ptr), 8u) - (u64)(buf_ptr)) + sizeof(u64) +             \
                                        ALIGN_UP_POW2((slot_size_bytes), (alignment_value)) + ((alignment_value) - 1),     \
Last updated on