HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dassert.h File Reference
#include <cstdio>
#include <cstdlib>
#include <OpenImageIO/platform.h>
+ Include dependency graph for dassert.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ASSERT(x)
 
#define ASSERT_MSG(x, msg,...)
 
#define ASSERTMSG   ASSERT_MSG
 
#define DASSERT(x)   ASSERT(x)
 
#define DASSERT_MSG   ASSERT_MSG
 
#define DASSERTMSG   DASSERT_MSG
 
#define OIIO_STATIC_ASSERT(cond)   static_assert(cond, "")
 
#define OIIO_STATIC_ASSERT_MSG(cond, msg)   static_assert(cond, msg)
 

Detailed Description

Handy macros for debugging assertions.

  • ASSERT (if not already defined) is defined to check if a condition is met, and if not, calls ABORT with an error message indicating the module and line where it occurred.
  • ASSERT_MSG: like ASSERT, but takes printf-like extra arguments
  • DASSERT is the same as ASSERT when NDEBUG is not defined but a no-op when not in debug mode.
  • DASSERT_MSG: like DASSERT, but takes printf-like extra arguments
  • OIIO_STATIC_ASSERT(cond) : static assertion
  • OIIO_STATIC_ASSERT_MSG(cond,msg) : static assertion + message

The presumed usage is that you want ASSERT for dire conditions that must be checked at runtime even in an optimized build. DASSERT is for checks we should do for debugging, but that we don't want to bother with in a shipping optimized build.

In both cases, these are NOT a substitute for actual error checking and recovery! Never ASSERT or DASSERT to check invalid user input, for example. They should be used only to verify that there aren't errors in the code that are so severe that there is no point even trying to recover gracefully.

Definition in file dassert.h.

Macro Definition Documentation

#define ASSERT (   x)
Value:
? ((void)0) \
: (std::fprintf(stderr, "%s:%u: failed assertion '%s'\n", \
__FILE__, __LINE__, #x), \
abort()))
#define OIIO_LIKELY(x)
Definition: platform.h:233
void fprintf(FILE *file, const char *fmt, const Args &...args)
Definition: strutil.h:227
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
void
Definition: png.h:1083

ASSERT(condition) checks if the condition is met, and if not, prints an error message indicating the module and line where the error occurred and then aborts.

Definition at line 71 of file dassert.h.

#define ASSERT_MSG (   x,
  msg,
  ... 
)
Value:
? ((void)0) \
: (std::fprintf(stderr, "%s:%u: failed assertion '%s': " msg "\n", \
__FILE__, __LINE__, #x, __VA_ARGS__), \
abort()))
#define OIIO_LIKELY(x)
Definition: platform.h:233
void fprintf(FILE *file, const char *fmt, const Args &...args)
Definition: strutil.h:227
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
void
Definition: png.h:1083

ASSERT_MSG(condition,msg,...) is like ASSERT, but lets you add formatted output (a la printf) to the failure message.

Definition at line 82 of file dassert.h.

#define ASSERTMSG   ASSERT_MSG

Definition at line 91 of file dassert.h.

#define DASSERT (   x)    ASSERT(x)

DASSERT(condition) is just like ASSERT, except that it only is functional in DEBUG mode, but does nothing when in a non-DEBUG (optimized, shipping) build.

Definition at line 99 of file dassert.h.

#define DASSERT_MSG   ASSERT_MSG

DASSERT_MSG(condition,msg,...) is just like ASSERT_MSG, except that it only is functional in DEBUG mode, but does nothing when in a non-DEBUG (optimized, shipping) build.

Definition at line 109 of file dassert.h.

#define DASSERTMSG   DASSERT_MSG

Definition at line 116 of file dassert.h.

#define OIIO_STATIC_ASSERT (   cond)    static_assert(cond, "")

Define OIIO_STATIC_ASSERT and OIIO_STATIC_ASSERT_MSG as wrappers around static_assert and static_assert_msg, with appropriate fallbacks for older C++ standards.

Definition at line 128 of file dassert.h.

#define OIIO_STATIC_ASSERT_MSG (   cond,
  msg 
)    static_assert(cond, msg)

Definition at line 129 of file dassert.h.