As mentioned in other answers, static_assert() in C11 is doing exactly that. In earlier C versions it can be "simulated" with some compiler black magic:
#define static_assert(condition, text) ((void)sizeof(char[1 - 2 * !(condition)]))
This works exactly like the C11 version apart from the less elegant error message.