1 /* Copyright (C) 1991, 1992, 1994, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
20 * ANSI Standard: 4.2 DIAGNOSTICS <assert.h>
33 /* void assert (int expression);
35 If NDEBUG is defined, do nothing.
36 If not, and EXPRESSION is zero, print an error message and abort. */
40 #define assert(expr) ((void) 0)
42 /* void assert_perror (int errnum);
44 If NDEBUG is defined, do nothing. If not, and ERRNUM is not zero, print an
45 error message with the error text for ERRNUM and abort.
46 (This is a GNU extension.) */
49 #define assert_perror(errnum) ((void) 0)
52 #else /* Not NDEBUG. */
54 #include <sys/cdefs.h>
58 /* This prints an "Assertion failed" message and aborts. */
59 extern void __assert_fail
__P ((__const
char *__assertion
,
62 __const
char *__function
))
63 __attribute__ ((__noreturn__
));
65 /* Likewise, but prints the error text for ERRNUM. */
66 extern void __assert_perror_fail
__P ((int __errnum
,
69 __const
char *__function
))
70 __attribute__ ((__noreturn__
));
74 #define assert(expr) \
76 (__assert_fail (__STRING(expr), \
77 __FILE__, __LINE__, __ASSERT_FUNCTION), 0)))
80 #define assert_perror(errnum) \
81 ((void) ((errnum) && (__assert_perror_fail ((errnum), \
83 __ASSERT_FUNCTION), 0)))
86 /* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
87 which contains the name of the function currently being defined.
88 This is broken in G++ before version 2.6. */
89 #if (!defined (__GNUC__) || __GNUC__ < 2 || \
90 __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4))
91 #define __ASSERT_FUNCTION ((__const char *) 0)
93 #define __ASSERT_FUNCTION __PRETTY_FUNCTION__