Skip to content
Coşkun ERGAN edited this page Sep 21, 2019 · 1 revision

#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))

//#if BUILD_BUG_ON(Lib_Init_List) // #error "you screwed up struct mystruct again!" //#endif

#define ASSERT_CONCAT_(a, b) a##b #define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) /* These can't be used after statements in c89. / #ifdef COUNTER #define STATIC_ASSERT(e,m)
;enum { ASSERT_CONCAT(static_assert_, COUNTER) = 1/(int)(!!(e)) } #else /
This can't be used twice on the same line so ensure if using in headers

  • that the headers are not included twice (by wrapping in #ifndef...#endif)
  • Note it doesn't cause an issue when used on same line of separate modules
  • compiled with gcc -combine -fwhole-program. */ #define STATIC_ASSERT(e,m)
    ;enum { ASSERT_CONCAT(assert_line_, LINE) = 1/(int)(!!(e)) } #endif

STATIC_ASSERT(sizeof(Lib_Init_List)==8,"Hata var!");

#define compile_time_assert(cond)
extern char assertion[(cond) ? 1 : -1]

#define offsetof(TYPE, MEMBER)
((size_t) &((TYPE *)0)->MEMBER)

typedef struct { int field1; char field2; char field3; char field4; char field5; } SOME_STRUCT;

compile_time_assert(offsetof(SOME_STRUCT, field1) == 0); compile_time_assert(offsetof(SOME_STRUCT, field2) == 4); compile_time_assert(offsetof(SOME_STRUCT, field3) == 5); compile_time_assert(offsetof(SOME_STRUCT, field4) == 6); compile_time_assert(offsetof(SOME_STRUCT, field5) == 7); compile_time_assert(sizeof(SOME_STRUCT) == 8);

Clone this wiki locally