-
-
Save kvanbere/5906455 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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