From 928af73f231f3f447728fcf7c337e5126041a645 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 18 Jul 2014 16:05:46 +0000 Subject: [PATCH] added compiler hints for assertions git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@166 8ec27952-4edc-4aab-86aa-e87bb2611832 --- server/include/utils.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/include/utils.h b/server/include/utils.h index 7ecef73a1..cc832c07d 100644 --- a/server/include/utils.h +++ b/server/include/utils.h @@ -15,6 +15,12 @@ #include +#ifdef __GNUC__ + #define EXPECT(x, v) __builtin_expect(x, v) +#else + #define EXPECT(x) (x) +#endif + /* Some color escape codes for pretty log messages */ #define RED(str) "\x1B[31m" str "\x1B[0m" /**< Print str in red */ #define GRN(str) "\x1B[32m" str "\x1B[0m" /**< Print str in green */ @@ -70,7 +76,7 @@ struct timespec timespec_rate(double rate); /** Check assertion and exit if failed. */ #define assert(exp) do { \ - if (!(exp)) { \ + if (EXPECT(exp, 0)) { \ print(ERROR, "Assertion failed: '%s' in %s, %s:%d", \ #exp, __FUNCTION__, __BASE_FILE__, __LINE__); \ exit(EXIT_FAILURE); \