_Static_assert

From cppreference.com
< c‎ | keyword


_Static_assert evaluates a constant expression at compile time. If the expression is equal to 0, the compiler will produce an error message containing the string literal given as the second parameter.

[edit] Parameters

condition - constant expression
str - string literal

[edit] Return Value

(none)

[edit] Example

#define BUFFER_SIZE 2048
 
int main (int argc, char **argv)
{
	// Test if math works.
	_Static_assert(2 + 2 == 4, "Whoa dude!");
 
        // This will produce an error at compile time.
        _Static_assert(BUFFER_SIZE <= 1024, "BUFFER_SIZE is too big");
 
	return 0;
}