Sun Dec 17 15:56:35 1995 Miles Bader <miles@gnu.ai.mit.edu>
[glibc.git] / assert / assert.h
blob7f7fc7f733a2e7e81a63cce49158e36c47730ef8
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>
23 #ifdef _ASSERT_H
25 #undef _ASSERT_H
26 #undef assert
28 #endif /* assert.h */
30 #define _ASSERT_H 1
31 #include <features.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. */
38 #ifdef NDEBUG
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.) */
48 #ifdef __USE_GNU
49 #define assert_perror(errnum) ((void) 0)
50 #endif
52 #else /* Not NDEBUG. */
54 #include <sys/cdefs.h>
56 __BEGIN_DECLS
58 /* This prints an "Assertion failed" message and aborts. */
59 extern void __assert_fail __P ((__const char *__assertion,
60 __const char *__file,
61 unsigned int __line,
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,
67 __const char *__file,
68 unsigned int __line,
69 __const char *__function))
70 __attribute__ ((__noreturn__));
72 __END_DECLS
74 #define assert(expr) \
75 ((void) ((expr) || \
76 (__assert_fail (__STRING(expr), \
77 __FILE__, __LINE__, __ASSERT_FUNCTION), 0)))
79 #ifdef __USE_GNU
80 #define assert_perror(errnum) \
81 ((void) ((errnum) && (__assert_perror_fail ((errnum), \
82 __FILE__, __LINE__, \
83 __ASSERT_FUNCTION), 0)))
84 #endif
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)
92 #else
93 #define __ASSERT_FUNCTION __PRETTY_FUNCTION__
94 #endif
97 #endif /* NDEBUG. */