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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1,349 Views
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.

Labels (1)
Tags (1)
1 Reply

1,217 Views
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.