diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-11-16 17:01:02 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-11-16 17:01:53 -0500 |
commit | 78dca8153f802f271b4f2aeca33d967a075e485e (patch) | |
tree | caf18232cb7d5256efaa853373644e810e1af014 /libdimension/dimension | |
parent | b8cfc42881e7045a6c93fcd5b64b14cefa8d6c5c (diff) | |
download | dimension-78dca8153f802f271b4f2aeca33d967a075e485e.tar.xz |
Add a dmnsn_unreachable() macro.
Also rename inline.h to compiler.h.
Diffstat (limited to 'libdimension/dimension')
-rw-r--r-- | libdimension/dimension/compiler.h (renamed from libdimension/dimension/inline.h) | 11 | ||||
-rw-r--r-- | libdimension/dimension/error.h | 20 |
2 files changed, 24 insertions, 7 deletions
diff --git a/libdimension/dimension/inline.h b/libdimension/dimension/compiler.h index e17c60e..5ce8ce8 100644 --- a/libdimension/dimension/inline.h +++ b/libdimension/dimension/compiler.h @@ -20,10 +20,7 @@ /** * @file - * Inline function support. Handle inlines nicely without cheating and making - * them static. The DMNSN_INLINE macro is set appropriately for the version of - * C you're using, and non-inline versions are emitted in exactly one - * translation unit when necessary. + * Compiler abstractions. */ /** @@ -47,3 +44,9 @@ #define DMNSN_INLINE static #endif #endif + +#ifdef __GNUC__ + #define DMNSN_UNREACHABLE() __builtin_unreachable(); +#else + #define DMNSN_UNREACHABLE() +#endif diff --git a/libdimension/dimension/error.h b/libdimension/dimension/error.h index ae8ba01..894899a 100644 --- a/libdimension/dimension/error.h +++ b/libdimension/dimension/error.h @@ -39,8 +39,11 @@ * Report an error. * @param[in] str A string to print explaining the error. */ -#define dmnsn_error(str) \ - dmnsn_report_error(true, DMNSN_FUNC, __FILE__, __LINE__, str) +#define dmnsn_error(str) \ + do { \ + dmnsn_report_error(true, DMNSN_FUNC, __FILE__, __LINE__, str); \ + DMNSN_UNREACHABLE(); \ + } while (0) /** * @def dmnsn_assert @@ -54,12 +57,23 @@ #define dmnsn_assert(expr, str) \ do { \ if (!(expr)) { \ - dmnsn_error((str)); \ + dmnsn_error((str)); \ } \ } while (0) #endif /** + * @def dmnsn_unreachable + * Express that a line of code is unreachable. + * @param[in] str A string to print if the line is reached. + */ +#ifdef NDEBUG + #define dmnsn_unreachable(str) DMNSN_UNREACHABLE() +#else + #define dmnsn_unreachable(str) dmnsn_error((str)) +#endif + +/** * @internal * Called by dmnsn_warning() and dmnsn_error(); don't call directly. * @param[in] die Whether the error is fatal. |