From 4ec65def3f1bb8ce0b938f4536c1f9ec7f23bec7 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 22 Oct 1993 14:05:24 +0000 Subject: [PATCH] Modified to conform to ANSI C --- modules/src/assert/BadAssert.c | 2 ++ modules/src/assert/assert.3 | 2 +- modules/src/assert/assert.h | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/modules/src/assert/BadAssert.c b/modules/src/assert/BadAssert.c index 82c8222a2..c1cccb53d 100644 --- a/modules/src/assert/BadAssert.c +++ b/modules/src/assert/BadAssert.c @@ -24,6 +24,7 @@ wr_num(fd, n) sys_write(fd, s, 1); } +int _BadAssertion(file, lineno, assertion) char *file, *assertion; int lineno; @@ -36,4 +37,5 @@ _BadAssertion(file, lineno, assertion) sys_write(STDERR, assertion, strlen(assertion)); sys_write(STDERR, "\" failed\n", 9); sys_stop(S_ABORT); + return 0; } diff --git a/modules/src/assert/assert.3 b/modules/src/assert/assert.3 index d3da1cf3c..8f5f6ecb7 100644 --- a/modules/src/assert/assert.3 +++ b/modules/src/assert/assert.3 @@ -33,7 +33,7 @@ It causes a .IR sys_stop (S_ABORT) with a diagnostic comment on standard error. .PP -The assertions are enabled by defining the preprocessor constant DEBUG. +The assertions are disabled by defining the preprocessor constant NDEBUG. .SH DIAGNOSTICS .IR fn , line diff --git a/modules/src/assert/assert.h b/modules/src/assert/assert.h index 50cbb98ec..f630add3e 100644 --- a/modules/src/assert/assert.h +++ b/modules/src/assert/assert.h @@ -5,13 +5,20 @@ /* $Header$ */ /* A S S E R T I O N M A C R O D E F I N I T I O N */ -#ifdef DEBUG -#ifdef __STDC__ -#define assert(exp) ((exp) || _BadAssertion(__FILE__, __LINE__, #exp)) +/* This 'assert' definition can be used in a ,-expression. */ + +#ifndef NDEBUG +#if __STDC__ +int _BadAssertion(char *, int, char *); +#define assert(exp) ((void)((exp) || _BadAssertion(__FILE__, __LINE__, #exp))) #else /* Note: this macro uses parameter substitution inside strings */ #define assert(exp) ((exp) || _BadAssertion(__FILE__, __LINE__, "exp")) #endif #else -#define assert(exp) (1) -#endif /* DEBUG */ +#if __STDC__ +#define assert(exp) ((void)0) +#else +#define assert(exp) (0) +#endif +#endif /* NDEBUG */