OSDN Git Service

fix #37913
[jnethack/source.git] / include / lint.h
1 /* NetHack 3.6  lint.h  $NHDT-Date: 1449269910 2015/12/04 22:58:30 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.3 $ */
2 /* NetHack may be freely redistributed.  See license for details. */
3
4 /*
5  * Hacks to suppress compiler warnings.  Use with caution.
6  * Assumes it has been preceded by '#include "config.h"' but
7  * not necessarily by '#include "hack.h"'.
8  */
9 #ifndef LINT_H
10 #define LINT_H
11
12 /* cast away implicit const from a string literal (caller's responsibility
13    to ensure that) in order to avoid a warning from 'gcc -Wwrite-strings'
14    (also caller's responsibility to ensure it isn't actually modified!) */
15 #define nhStr(str) ((char *) str)
16
17 #if defined(GCC_WARN) && !defined(FORCE_ARG_USAGE)
18 #define FORCE_ARG_USAGE
19 #endif
20
21 #ifdef FORCE_ARG_USAGE
22 /* force an unused function argument to become used in an arbitrary
23    manner in order to suppress warning about unused function arguments;
24    viable for scalar and pointer arguments */
25 #define nhUse(arg) nhUse_dummy += (unsigned) arg;
26 extern unsigned nhUse_dummy;
27 #else
28 #define nhUse(arg) /*empty*/
29 #endif
30
31 /*
32  * This stuff isn't related to lint suppression but lives here to
33  * avoid cluttering up hack.h.
34  */
35 /* [DEBUG shouldn't be defined unless you know what you're doing...] */
36 #ifdef DEBUG
37 #define showdebug(file) debugcore(file, TRUE)
38 #define explicitdebug(file) debugcore(file, FALSE)
39 #define ifdebug(stmt)                   \
40     do {                                \
41         if (showdebug(__FILE__)) {      \
42             stmt;                       \
43         }                               \
44     } while (0)
45 #ifdef _MSC_VER
46 /* if we have microsoft's C runtime we can use these instead */
47 #include <crtdbg.h>
48 #define crtdebug(stmt)                  \
49     do {                                \
50         if (showdebug(__FILE__)) {      \
51             stmt;                       \
52         }                               \
53         _RPT0(_CRT_WARN, "\n");         \
54     } while (0)
55 #define debugpline0(str) crtdebug(_RPT0(_CRT_WARN, str))
56 #define debugpline1(fmt, arg) crtdebug(_RPT1(_CRT_WARN, fmt, arg))
57 #define debugpline2(fmt, a1, a2) crtdebug(_RPT2(_CRT_WARN, fmt, a1, a2))
58 #define debugpline3(fmt, a1, a2, a3) \
59     crtdebug(_RPT3(_CRT_WARN, fmt, a1, a2, a3))
60 #define debugpline4(fmt, a1, a2, a3, a4) \
61     crtdebug(_RPT4(_CRT_WARN, fmt, a1, a2, a3, a4))
62 #else
63 /* these don't require compiler support for C99 variadic macros */
64 #define debugpline0(str) ifdebug(pline(str))
65 #define debugpline1(fmt, arg) ifdebug(pline(fmt, arg))
66 #define debugpline2(fmt, a1, a2) ifdebug(pline(fmt, a1, a2))
67 #define debugpline3(fmt, a1, a2, a3) ifdebug(pline(fmt, a1, a2, a3))
68 #define debugpline4(fmt, a1, a2, a3, a4) ifdebug(pline(fmt, a1, a2, a3, a4))
69 #endif
70 #else
71 #define debugpline0(str)                 /*empty*/
72 #define debugpline1(fmt, arg)            /*empty*/
73 #define debugpline2(fmt, a1, a2)         /*empty*/
74 #define debugpline3(fmt, a1, a2, a3)     /*empty*/
75 #define debugpline4(fmt, a1, a2, a3, a4) /*empty*/
76 #endif                                   /*DEBUG*/
77
78 #endif /* LINT_H */