Is there a static (compile time) version of ASSERT()?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Is there a static (compile time) version of ASSERT()?

1,350 次查看
robertpoor
Senior Contributor I

Is there a compile-time form of ASSERT() available in KDS?  It would be handy when checking on size of packed bit arrays, or the address of system registers, etc.

 

I am using a "polyfill" version of STATIC_ASSERT() from Compile time assertions in C , but it would be great if there was a natively supported version instead.

标签 (1)
标记 (1)
1 回复

1,218 次查看
robertpoor
Senior Contributor I

I just stumbled across the answer: yes there is:

_Static_assert(1==2, "whoa");

...will cause the compilation to fail with a message of the form:

In ../sources/assert_test.h:194:1: error: static assertion failed: "whoa"

_Static_assert(1==2, "whoa");

On the other hand, 

_Static_assert(1==1, "whoa");

... will compile without error.