Home / Compile-time asserts in C

Asserts are good. Compile-time asserts are even better. Here’s how to define and use them in C. c #ifndef CASSERT #define CASSERT( exp, name ) typedef int dummy##name [ (exp ) ? 1 : -1 ]; #endif CASSERT( sizeof(int16_t) == 2, int16_t_is_two_bytes )

Go to index of articles.