Skip to content

Instantly share code, notes, and snippets.

@kvanbere
Forked from anonymous/assert.c
Created July 2, 2013 02:50
Show Gist options
  • Save kvanbere/5906455 to your computer and use it in GitHub Desktop.
Save kvanbere/5906455 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#if defined(__GNUC__)
#define unreachable() \
__builtin_unreachable()
#define assertion(cond) \
do \
{ \
if (!(cond)) \
unreachable(); \
} while (0)
#elif defined(_MSC_VER)
#define unreachable() \
__assume(false)
#define assertion(cond) \
__assume((cond))
#else
#define unreachable() \
do { } while(0)
#define assertion(cond) \
assert((cond))
#endif
#if defined(__GNUC__)
#define unlikely_if(cond) \
if (__builtin_expect((cond), 0))
#define likely_if(cond) \
if (__builtin_expect((cond), !0))
#else
#define unlikely_if if
#define likely_if if
#endif
int main()
{
int a;
a = rand();
assertion(a == 99);
if (a == 99)
printf("Hurr");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment