Modified to conform to ANSI C

This commit is contained in:
ceriel 1993-10-22 14:05:24 +00:00
parent 799f0600ef
commit 4ec65def3f
3 changed files with 15 additions and 6 deletions

View file

@ -24,6 +24,7 @@ wr_num(fd, n)
sys_write(fd, s, 1); sys_write(fd, s, 1);
} }
int
_BadAssertion(file, lineno, assertion) _BadAssertion(file, lineno, assertion)
char *file, *assertion; char *file, *assertion;
int lineno; int lineno;
@ -36,4 +37,5 @@ _BadAssertion(file, lineno, assertion)
sys_write(STDERR, assertion, strlen(assertion)); sys_write(STDERR, assertion, strlen(assertion));
sys_write(STDERR, "\" failed\n", 9); sys_write(STDERR, "\" failed\n", 9);
sys_stop(S_ABORT); sys_stop(S_ABORT);
return 0;
} }

View file

@ -33,7 +33,7 @@ It causes a
.IR sys_stop (S_ABORT) .IR sys_stop (S_ABORT)
with a diagnostic comment on standard error. with a diagnostic comment on standard error.
.PP .PP
The assertions are enabled by defining the preprocessor constant DEBUG. The assertions are disabled by defining the preprocessor constant NDEBUG.
.SH DIAGNOSTICS .SH DIAGNOSTICS
.IR fn , .IR fn ,
line line

View file

@ -5,13 +5,20 @@
/* $Header$ */ /* $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 */ /* 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 /* This 'assert' definition can be used in a ,-expression. */
#ifdef __STDC__
#define assert(exp) ((exp) || _BadAssertion(__FILE__, __LINE__, #exp)) #ifndef NDEBUG
#if __STDC__
int _BadAssertion(char *, int, char *);
#define assert(exp) ((void)((exp) || _BadAssertion(__FILE__, __LINE__, #exp)))
#else #else
/* Note: this macro uses parameter substitution inside strings */ /* Note: this macro uses parameter substitution inside strings */
#define assert(exp) ((exp) || _BadAssertion(__FILE__, __LINE__, "exp")) #define assert(exp) ((exp) || _BadAssertion(__FILE__, __LINE__, "exp"))
#endif #endif
#else #else
#define assert(exp) (1) #if __STDC__
#endif /* DEBUG */ #define assert(exp) ((void)0)
#else
#define assert(exp) (0)
#endif
#endif /* NDEBUG */