Consider a function
void f() {
assert(condition);
...
}
In debug mode, where asserts are enabled, the compiler is free to assume
This can't be done in portable C or C++.
Some compilers provide intrinsic functions such as __assume (for MSVC) and __builtin_unreachable (for GCC, ICC, and Clang), that can be used for this purpose.
For example:
void f() {
__assume(condition); //For MSVC
/*...*/
}
void f() {
if (!condition) __builtin_unreachable(); //for GCC and Clang
/*...*/
}