K-HHC
C++ Header-only Library for Hexahexacontadecimal Encoding/Decoding
Loading...
Searching...
No Matches
Namespaces | Macros | Functions
hhc_assert.hpp File Reference
#include <cstdlib>
#include <iostream>
Include dependency graph for hhc_assert.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  hhc
 
namespace  hhc::detail
 

Macros

#define HHC_NO_PROFILE
 
#define HHC_HAVE_BACKTRACE   0
 
#define HHC_HAVE_STACKWALK   0
 
#define HHC_ASSERT(expr)
 HHC assertion macro.
 
#define HHC_ASSERT_MSG(expr, msg)
 HHC assertion macro with custom message.
 
#define HHC_UNREACHABLE(msg)
 Mark a code path as unreachable.
 

Functions

void hhc::detail::flush_coverage_profile ()
 
HHC_NO_PROFILE void hhc::detail::print_stack_trace ()
 Print stack trace (debug builds only)
 
HHC_NO_PROFILE void hhc::detail::assertion_failed (const char *expression, const char *file, const int line, const char *function)
 Handle assertion failure.
 

Macro Definition Documentation

◆ HHC_ASSERT

#define HHC_ASSERT (   expr)
Value:
do { \
if (!(expr)) { \
::hhc::detail::assertion_failed( \
#expr, \
__FILE__, \
__LINE__, \
__func__ \
); \
} \
} while (0)

HHC assertion macro.

Unlike standard assert(), this macro:

  • Is ALWAYS enabled (both debug and release builds)
  • In debug: provides detailed error message with stack trace
  • In release: generates trap instruction (optimization hint)

Use this for conditions that should NEVER be false. If they are, it indicates a critical bug in the library code.

Example: HHC_ASSERT(pointer != nullptr);

Parameters
exprThe expression to check (must evaluate to true)

◆ HHC_ASSERT_MSG

#define HHC_ASSERT_MSG (   expr,
  msg 
)
Value:
do { \
if (!(expr)) { \
::hhc::detail::assertion_failed( \
#expr " (" msg ")", \
__FILE__, \
__LINE__, \
__func__ \
); \
} \
} while (0)

HHC assertion macro with custom message.

Same as HHC_ASSERT but allows a custom error message.

Example: HHC_ASSERT_MSG(size > 0, "Size must be positive");

Parameters
exprThe expression to check
msgCustom error message (string literal)

◆ HHC_HAVE_BACKTRACE

#define HHC_HAVE_BACKTRACE   0

◆ HHC_HAVE_STACKWALK

#define HHC_HAVE_STACKWALK   0

◆ HHC_NO_PROFILE

#define HHC_NO_PROFILE

◆ HHC_UNREACHABLE

#define HHC_UNREACHABLE (   msg)
Value:
"Unreachable code: " msg, \
__FILE__, \
__LINE__, \
__func__ \
)
HHC_NO_PROFILE void assertion_failed(const char *expression, const char *file, const int line, const char *function)
Handle assertion failure.
Definition hhc_assert.hpp:139

Mark a code path as unreachable.

Use this for code paths that should never be reached. In debug: aborts with error message In release: generates trap instruction (optimization hint)

Example: switch (value) { case 1: return foo(); case 2: return bar(); default: HHC_UNREACHABLE("Invalid value"); }

Parameters
msgExplanation of why this should be unreachable