static_assert in OC


Version: 2027

Type: Features

Category: Programming

Subcategory: Origin C

Jira: ORG-33846


Example:

#define MY_CONST 4
int test_int()
{
	return 4;
}
void test()
{
	static_assert ( sizeof(int) == 4);	// pass, no message
	static_assert ( sizeof(int) == 4 && 2 > 1, "pass 1"); // pass
	static_assert ( sizeof(int) != 4, "fail 1");	// should fail
	static_assert (MY_CONST != 4, "fail 2");	// should fail
	static_assert ( test_int() == 4);	// should not compile, because the expression is not compile-time constant
}