Home
Software
Writings
Compile-time asserts in C
c programming
Asserts are good. Compile-time asserts are even better. Here’s how to define and use them in 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 )
Written on Jan 13 2006. Topics: c, programming.
home
Found a mistake, have a comment? Let me know.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you: