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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

1,370件の閲覧回数
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,238件の閲覧回数
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.