]> sourceware.org Git - glibc.git/blame - assert/assert.h
Update.
[glibc.git] / assert / assert.h
CommitLineData
8fb81470 1/* Copyright (C) 1991,92,94,95,96,97,98,99,2000 Free Software Foundation, Inc.
ba1ffaa1 2 This file is part of the GNU C Library.
28f540f4 3
ba1ffaa1
UD
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.
28f540f4 8
ba1ffaa1
UD
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.
28f540f4 13
ba1ffaa1
UD
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 not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
28f540f4
RM
18
19/*
d1646309 20 * ISO C99 Standard: 7.2 Diagnostics <assert.h>
28f540f4
RM
21 */
22
23#ifdef _ASSERT_H
24
40a55d20
UD
25# undef _ASSERT_H
26# undef assert
27
28# ifdef __USE_GNU
29# undef assert_perror
30# endif
28f540f4
RM
31
32#endif /* assert.h */
33
34#define _ASSERT_H 1
35#include <features.h>
36
37/* void assert (int expression);
38
39 If NDEBUG is defined, do nothing.
40 If not, and EXPRESSION is zero, print an error message and abort. */
41
42#ifdef NDEBUG
43
f21acc89 44# define assert(expr) ((void) 0)
28f540f4
RM
45
46/* void assert_perror (int errnum);
47
48 If NDEBUG is defined, do nothing. If not, and ERRNUM is not zero, print an
49 error message with the error text for ERRNUM and abort.
50 (This is a GNU extension.) */
51
f21acc89
UD
52# ifdef __USE_GNU
53# define assert_perror(errnum) ((void) 0)
54# endif
28f540f4
RM
55
56#else /* Not NDEBUG. */
57
28f540f4
RM
58__BEGIN_DECLS
59
60/* This prints an "Assertion failed" message and aborts. */
c1422e5b
UD
61extern void __assert_fail (__const char *__assertion, __const char *__file,
62 unsigned int __line, __const char *__function)
63 __THROW __attribute__ ((__noreturn__));
28f540f4
RM
64
65/* Likewise, but prints the error text for ERRNUM. */
c1422e5b
UD
66extern void __assert_perror_fail (int __errnum, __const char *__file,
67 unsigned int __line,
68 __const char *__function)
69 __THROW __attribute__ ((__noreturn__));
28f540f4 70
8fb81470
UD
71
72/* The following is not at all used here but needed for standard
73 compliance. */
74extern void __assert (const char *__assertion, const char *__file, int __line)
75 __THROW __attribute__ ((__noreturn__));
76
77
28f540f4
RM
78__END_DECLS
79
f21acc89
UD
80# define assert(expr) \
81 ((void) ((expr) ? 0 : \
28f540f4
RM
82 (__assert_fail (__STRING(expr), \
83 __FILE__, __LINE__, __ASSERT_FUNCTION), 0)))
84
f21acc89
UD
85# ifdef __USE_GNU
86# define assert_perror(errnum) \
6591c335
UD
87 ((void) (!(errnum) ? 0 : (__assert_perror_fail ((errnum), \
88 __FILE__, __LINE__, \
89 __ASSERT_FUNCTION), 0)))
f21acc89 90# endif
28f540f4
RM
91
92/* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
93 which contains the name of the function currently being defined.
05cc5bd9
UD
94 This is broken in G++ before version 2.6.
95 C9x has a similar variable called __func__, but prefer the GCC one since
96 it demangles C++ function names. */
d0db5f48 97# if defined __cplusplus ? __GNUC_PREREQ (2, 6) : __GNUC_PREREQ (2, 4)
05cc5bd9 98# define __ASSERT_FUNCTION __PRETTY_FUNCTION__
05cc5bd9
UD
99# else
100# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
101# define __ASSERT_FUNCTION __func__
102# else
103# define __ASSERT_FUNCTION ((__const char *) 0)
104# endif
f21acc89 105# endif
28f540f4 106
28f540f4 107#endif /* NDEBUG. */
This page took 0.110749 seconds and 5 git commands to generate.