diff --git a/include/misc.h b/include/misc.h index 29a3671c..3217c39a 100644 --- a/include/misc.h +++ b/include/misc.h @@ -82,6 +82,13 @@ extern void (*oops_handler)(void); #define BUILD_ASSERT_ONE(cond) \ (sizeof(char[1 - 2 * !(cond)])) +/* + * Assert constant expression @cond. + * If @cond is zero, force a compilation error. + */ +#define BUILD_ASSERT(cond) \ + ((void)BUILD_ASSERT_ONE(cond)) + void exit_nomem(void) ATTRIBUTE((noreturn)); /* return codes from command routines */ diff --git a/src/lib/subs/show.c b/src/lib/subs/show.c index b214af15..0ec50156 100644 --- a/src/lib/subs/show.c +++ b/src/lib/subs/show.c @@ -516,7 +516,7 @@ show_product(int tlev) pp->p_sname, pp->p_type < 0 ? ' ' : ichr[pp->p_type].i_mnem, pp->p_cost); - (void)CANT_HAPPEN(MAXPRCON > 3); /* output has only three columns */ + BUILD_ASSERT(MAXPRCON <= 3); /* output has only three columns */ for (i = 0; i < 3; i++) { if (i < MAXPRCON && pp->p_camt[i] && pp->p_ctype[i] > I_NONE && pp->p_ctype[i] <= I_MAX)