File: assert.h

package info (click to toggle)
lookup 1.08b-5
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 1,108 kB
  • ctags: 1,305
  • sloc: ansic: 12,634; makefile: 236; perl: 174; sh: 53
file content (69 lines) | stat: -rw-r--r-- 2,423 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Jeffrey Friedl
 * Omron Corporation			ʳ
 * Nagaokakyoshi, Japan			617Ĺ
 *
 * jfriedl@nff.ncl.omron.co.jp
 *
 * This work is placed under the terms of the GNU General Purpose License
 * (the "GNU Copyleft").
 */
#ifndef __ASSERT_H__
#define __ASSERT_H__

#ifndef macro_start /* just in case this file is included stand-alone */
# define macro_start  do
# define macro_end    while (0)
#endif

/*
 * When NDEBUG (no debug) is on, these asserts become (almost) nothing.
 */
#ifdef NDEBUG
# define assert(expr)          macro_start { /* nothing */ } macro_end
# define soft_assert(expr)     macro_start { /* nothing */ } macro_end
# define kibishii_assert(expr) macro_start { /* nothing */ } macro_end
#else

#ifndef __OUTPUT_H__
#include "output.h"
#endif

/*
 * Regular assert -- die if EXPR is not true.
 */
#define assert(expr)                                                         \
macro_start {                                                                \
    if (!(expr))                                                             \
    {                                                                        \
	die("\nassert(" #expr ") failed \"%s\" line %d.\n",                  \
		      __FILE__, __LINE__);                                   \
    }                                                                        \
} macro_end

/*
 * just warn (if EXPR is not true.)
 */
#define soft_assert(expr)                                                    \
macro_start {                                                                \
    if (!(expr))                                                             \
    {                                                                        \
	warn("\nassert(" #expr ") failed \"%s\" line %d.\n",                 \
		      __FILE__, __LINE__);                                   \
    }                                                                        \
} macro_end

/*
 * Kibishii debug stuff is normally not on unless specifically requested,
 * such as under special debugging situations, or development times.
 * When on, it's just like a soft assert. When off, it's nothing.
 */
#ifndef KIBISHII_DEBUG
# define kibishii_assert(expr) macro_start { /* nothing */ } macro_end
#else
# define kibishii_assert(expr) soft_assert(expr)
#endif /* KIBISHII_DEBUG */


#endif /* NDEBUG wrapper */
#endif /* file wrapper */