EBGeometry
Compact, header-only C++ library for fast evaluation of signed distance functions
Loading...
Searching...
No Matches
Macros
EBGeometry_Macros.hpp File Reference

Utility macros for EBGeometry. More...

#include <cstdio>
#include <cstdlib>
Include dependency graph for EBGeometry_Macros.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define EBGEOMETRY_EXPECT(cond)   (static_cast<void>(sizeof((cond))))
 Runtime precondition assertion for EBGeometry.
 

Detailed Description

Utility macros for EBGeometry.

Author
Robert Marskar

Macro Definition Documentation

◆ EBGEOMETRY_EXPECT

#define EBGEOMETRY_EXPECT (   cond)    (static_cast<void>(sizeof((cond))))

Runtime precondition assertion for EBGeometry.

When EBGEOMETRY_ENABLE_ASSERTIONS is defined (e.g. via -DEBGEOMETRY_ENABLE_ASSERTIONS on the compiler command line, in CXXFLAGS for GNU Make, or via CMake's target_compile_definitions), this macro evaluates cond and, if it is false, prints a diagnostic message to stderr and calls std::abort().

When EBGEOMETRY_ENABLE_ASSERTIONS is not defined the macro does not evaluate the condition at all: it expands to a discarded sizeof, which is an unevaluated context. The expression is therefore never executed (guaranteed zero runtime cost and no side effects, even at -O0), yet is still parsed – so it stays syntax-checked and any variables/parameters that appear only inside assertions are still considered "used" and do not trigger unused-entity warnings.

Enabling assertions
# CMake
target_compile_definitions(MyTarget PRIVATE EBGEOMETRY_ENABLE_ASSERTIONS)
# GNU Make
CXXFLAGS += -DEBGEOMETRY_ENABLE_ASSERTIONS
# Command line
g++ -DEBGEOMETRY_ENABLE_ASSERTIONS ...
Parameters
condBoolean-convertible expression to test.