Compile Time Assertion..
The most seen assertion are during runtime, but this one is at compile time, to give the error more quickly..
I do not quite understand why need this kind of check.. The following is code from OVS..
#define BUILD_ASSERT(EXPR) \ typedef char AssertOnCompileFailed[(EXPR)?1:-1] #define BUILD_ASSERT_DECL(EXPR) BUILD_ASSERT(EXPR) typedef struct _NlMsgErr { INT error; NL_MSG_HDR nlMsg; } NL_MSG_ERR, *PNL_MSG_ERR; BUILD_ASSERT_DECL(sizeof(NL_MSG_ERR)==20);
I think maybe the typedef of struct is constructed at compile time, so assert at compile time is not a bad idea..
Anyone is permitted to copy/use the contents and codes from this blog.
Sansna is not going to guarantee anything, Sansna will not take any responsibility of any results after using these codes/contents.