Kohi Game Engine
asserts.h File Reference

This file contains assertion functions to be used throughout the codebase. More...

#include "defines.h"

Go to the source code of this file.

Macros

#define KASSERTIONS_ENABLED
 
#define debugBreak()   __builtin_trap()
 Causes a debug breakpoint to be hit. More...
 
#define KASSERT(expr)
 Asserts the provided expression to be true, and logs a failure if not. Also triggers a breakpoint if debugging. More...
 
#define KASSERT_MSG(expr, message)
 Asserts the provided expression to be true, and logs a failure if not. Allows the user to specify a message to accompany the failure. Also triggers a breakpoint if debugging. More...
 
#define KASSERT_DEBUG(expr)
 

Functions

KAPI void report_assertion_failure (const char *expression, const char *message, const char *file, i32 line)
 Reports an assertion failure. Note that this is not the assertion itself, just a reporting of an assertion failure that has already occurred. More...
 

Detailed Description

This file contains assertion functions to be used throughout the codebase.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
1.0
Date
2022-01-10

Macro Definition Documentation

◆ debugBreak

#define debugBreak ( )    __builtin_trap()

Causes a debug breakpoint to be hit.

◆ KASSERT

#define KASSERT (   expr)
Value:
{ \
if (expr) { \
} else { \
report_assertion_failure(#expr, "", __FILE__, __LINE__); \
debugBreak(); \
} \
}

Asserts the provided expression to be true, and logs a failure if not. Also triggers a breakpoint if debugging.

Parameters
exprThe expression to be evaluated.

◆ KASSERT_DEBUG

#define KASSERT_DEBUG (   expr)

◆ KASSERT_MSG

#define KASSERT_MSG (   expr,
  message 
)
Value:
{ \
if (expr) { \
} else { \
report_assertion_failure(#expr, message, __FILE__, __LINE__); \
debugBreak(); \
} \
}

Asserts the provided expression to be true, and logs a failure if not. Allows the user to specify a message to accompany the failure. Also triggers a breakpoint if debugging.

Parameters
exprThe expression to be evaluated.
messageThe message to be reported along with the assertion failure.

◆ KASSERTIONS_ENABLED

#define KASSERTIONS_ENABLED

Function Documentation

◆ report_assertion_failure()

KAPI void report_assertion_failure ( const char *  expression,
const char *  message,
const char *  file,
i32  line 
)

Reports an assertion failure. Note that this is not the assertion itself, just a reporting of an assertion failure that has already occurred.

Parameters
expressionThe expression to be reported.
messageA custom message to be reported, if provided.
fileThe path and name of the file containing the expression.
lineThe line number in the file where the assertion failure occurred.