]> git.sesse.net Git - movit/blobdiff - util.h
Add (safe) asserts around all Effect::set_* return values, and add warnings for not...
[movit] / util.h
diff --git a/util.h b/util.h
index 082d1146a7f4c86c2d935ffeaa62307f6575b884..b01d62c00f00588a21b2587e6387f649b6b3bdc1 100644 (file)
--- a/util.h
+++ b/util.h
@@ -49,4 +49,17 @@ void combine_two_samples(float w1, float w2, float *offset, float *total_weight,
 #define check_error() { int err = glGetError(); if (err != GL_NO_ERROR) { printf("GL error 0x%x at %s:%d\n", err, __FILE__, __LINE__); exit(1); } }
 #endif
 
+#ifdef __GNUC__
+#define MUST_CHECK_RESULT __attribute__((warn_unused_result))
+#else
+#define MUST_CHECK_RESULT 
+#endif
+
+// CHECK() is like assert(), but retains any side effects no matter the compilation mode.
+#ifdef NDEBUG
+#define CHECK(x) (void)(x)
+#else
+#define CHECK(x) do { bool ok = x; if (!ok) { fprintf(stderr, "%s:%d: %s: Assertion `%s' failed.\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #x); abort(); } } while (false)
+#endif
+
 #endif // !defined(_UTIL_H)