OPIC
Object Persistence In C
Macros
Assert

Macros

#define op_assert(X, ...)
 assert with diagnosis messages. This macro emits the function, file, line nuber and stack traces. More...
 
#define op_assert_diagnose(X, cb, ...)
 assert with callback. More...
 

Detailed Description

Macro Definition Documentation

◆ op_assert

#define op_assert (   X,
  ... 
)

#include <opic/common/op_assert.h>

Value:
do{ \
if (op_unlikely(!(X))) { \
fprintf(stderr,"Assertion failed: %s (%s:%d)\n", \
__func__, __FILE__, __LINE__); \
fprintf(stderr,"Error message: " __VA_ARGS__); \
op_stacktrace(stderr); \
} \
} while(0)

assert with diagnosis messages. This macro emits the function, file, line nuber and stack traces.

Parameters
XA C expression user expects to be true
...printf like format string and arguments.

Example usage:

int x = 2;
op_assert(x == 1, "x should be 1 but was %d", x);

Definition at line 77 of file op_assert.h.

◆ op_assert_diagnose

#define op_assert_diagnose (   X,
  cb,
  ... 
)

#include <opic/common/op_assert.h>

Value:
do { \
if (op_unlikely(!(X))) { \
fprintf(stderr,"Assertion failed: %s (%s:%d)\n", \
__func__, __FILE__, __LINE__); \
(cb)(__VA_ARGS__); \
op_stacktrace(stderr); \
} \
} while(0)

assert with callback.

Parameters
XA C expression user expects to be true
cbA callback function.
...Arguments to pass to the callback function.

When the assertion failed, it first print the function name, file name, and line number where this macro was written. Then it invokes the callback with the arguments user specified. Finally it prints the stacktrace.

Example usage:

void my_diagnose(int x) {
fprintf(stderr, "x should be 1 but was %d", x)
}
int x = 2;
op_assert_diagnose(x == 1, &my_diagnose, x);

Definition at line 111 of file op_assert.h.