]> git.pond.sub.org Git - empserver/commitdiff
Convert run-time to build-time assertion
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 4 Jul 2015 14:19:16 +0000 (16:19 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 5 Dec 2015 11:43:28 +0000 (12:43 +0100)
There's just one, in show_product().

Use new BUILD_ASSERT() there, because its contract is even simpler
than BUILD_ASSERT_ONE()'s.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
include/misc.h
src/lib/subs/show.c

index 29a3671c78c8c3bda5f91675649c583a5d4b12fa..3217c39aedd18cded057faeb3e7eabe35ed30682 100644 (file)
@@ -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 */
index b214af15d8a321b3968699325a0717eb8ba12069..0ec5015696af0666cb438100ac75d9c1deaddd1f 100644 (file)
@@ -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)