Source:NetHack 3.6.1/include/tradstdc.h

From NetHackWiki
(Redirected from Tradstdc.h)
Jump to: navigation, search

Below is the full text to tradstdc.h from the source code of NetHack 3.6.1. To link to a particular line, write [[Source:NetHack 3.6.1/include/tradstdc.h#line123]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1.  /* NetHack 3.6	tradstdc.h	$NHDT-Date: 1501803107 2017/08/03 23:31:47 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.29 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /*-Copyright (c) Robert Patrick Rankin, 2006. */
  4.  /* NetHack may be freely redistributed.  See license for details. */
  5.  
  6.  #ifndef TRADSTDC_H
  7.  #define TRADSTDC_H
  8.  
  9.  #if defined(DUMB) && !defined(NOVOID)
  10.  #define NOVOID
  11.  #endif
  12.  
  13.  #ifdef NOVOID
  14.  #define void int
  15.  #endif
  16.  
  17.  /*
  18.   * Borland C provides enough ANSI C compatibility in its Borland C++
  19.   * mode to warrant this.  But it does not set __STDC__ unless it compiles
  20.   * in its ANSI keywords only mode, which prevents use of <dos.h> and
  21.   * far pointer use.
  22.   */
  23.  #if (defined(__STDC__) || defined(__TURBOC__)) && !defined(NOTSTDC)
  24.  #define NHSTDC
  25.  #endif
  26.  
  27.  #if defined(ultrix) && defined(__STDC__) && !defined(__LANGUAGE_C)
  28.  /* Ultrix seems to be in a constant state of flux.  This check attempts to
  29.   * set up ansi compatibility if it wasn't set up correctly by the compiler.
  30.   */
  31.  #ifdef mips
  32.  #define __mips mips
  33.  #endif
  34.  #ifdef LANGUAGE_C
  35.  #define __LANGUAGE_C LANGUAGE_C
  36.  #endif
  37.  #endif
  38.  
  39.  /*
  40.   * ANSI X3J11 detection.
  41.   * Makes substitutes for compatibility with the old C standard.
  42.   */
  43.  
  44.  /* Decide how to handle variable parameter lists:
  45.   * USE_STDARG means use the ANSI <stdarg.h> facilities (only ANSI compilers
  46.   * should do this, and only if the library supports it).
  47.   * USE_VARARGS means use the <varargs.h> facilities.  Again, this should only
  48.   * be done if the library supports it.  ANSI is *not* required for this.
  49.   * Otherwise, the kludgy old methods are used.
  50.   * The defaults are USE_STDARG for ANSI compilers, and USE_OLDARGS for
  51.   * others.
  52.   */
  53.  
  54.  /* #define USE_VARARGS */ /* use <varargs.h> instead of <stdarg.h> */
  55.  /* #define USE_OLDARGS */ /* don't use any variable argument facilities */
  56.  
  57.  #if defined(apollo) /* Apollos have stdarg(3) but not stdarg.h */
  58.  #define USE_VARARGS
  59.  #endif
  60.  
  61.  #if defined(NHSTDC) || defined(ULTRIX_PROTO) || defined(MAC)
  62.  #if !defined(USE_VARARGS) && !defined(USE_OLDARGS) && !defined(USE_STDARG)
  63.  #define USE_STDARG
  64.  #endif
  65.  #endif
  66.  
  67.  #ifdef NEED_VARARGS /* only define these if necessary */
  68.  /*
  69.   * These have changed since 3.4.3.  VA_END() now provides an explicit
  70.   * closing brace to complement VA_DECL()'s hidden opening brace, so code
  71.   * started with VA_DECL() needs an extra opening brace to complement
  72.   * the explicit final closing brace.  This was done so that the source
  73.   * would look less strange, where VA_DECL() appeared to introduce a
  74.   * function whose opening brace was missing; there are now visible and
  75.   * invisible braces at beginning and end.  Sample usage:
  76.   void foo VA_DECL(int, arg)  --macro expansion has a hidden opening brace
  77.   {  --new, explicit opening brace (actually introduces a nested block)
  78.   VA_START(bar);
  79.   ...code for foo...
  80.   VA_END();  --expansion now provides a closing brace for the nested block
  81.   }  --existing closing brace, still pairs with the hidden one in VA_DECL()
  82.   * Reading the code--or using source browsing tools which match braces--
  83.   * results in seeing a matched set of braces.  Usage of VA_END() is
  84.   * potentially trickier, but nethack uses it in a straightforward manner.
  85.   */
  86.  
  87.  #ifdef USE_STDARG
  88.  #include <stdarg.h>
  89.  #define VA_DECL(typ1, var1) \
  90.      (typ1 var1, ...)        \
  91.      {                       \
  92.          va_list the_args;
  93.  #define VA_DECL2(typ1, var1, typ2, var2) \
  94.      (typ1 var1, typ2 var2, ...)          \
  95.      {                                    \
  96.          va_list the_args;
  97.  #define VA_INIT(var1, typ1)
  98.  #define VA_NEXT(var1, typ1) var1 = va_arg(the_args, typ1)
  99.  #define VA_ARGS the_args
  100.  #define VA_START(x) va_start(the_args, x)
  101.  #define VA_END()      \
  102.      va_end(the_args); \
  103.      }
  104.  #define VA_PASS1(a1) a1
  105.  #if defined(ULTRIX_PROTO) && !defined(_VA_LIST_)
  106.  #define _VA_LIST_ /* prevents multiple def in stdio.h */
  107.  #endif
  108.  #else
  109.  
  110.  #ifdef USE_VARARGS
  111.  #include <varargs.h>
  112.  #define VA_DECL(typ1, var1) \
  113.      (va_alist) va_dcl       \
  114.      {                       \
  115.          va_list the_args;   \
  116.          typ1 var1;
  117.  #define VA_DECL2(typ1, var1, typ2, var2) \
  118.      (va_alist) va_dcl                    \
  119.      {                                    \
  120.          va_list the_args;                \
  121.          typ1 var1;                       \
  122.          typ2 var2;
  123.  #define VA_ARGS the_args
  124.  #define VA_START(x) va_start(the_args)
  125.  #define VA_INIT(var1, typ1) var1 = va_arg(the_args, typ1)
  126.  #define VA_NEXT(var1, typ1) var1 = va_arg(the_args, typ1)
  127.  #define VA_END()      \
  128.      va_end(the_args); \
  129.      }
  130.  #define VA_PASS1(a1) a1
  131.  #else
  132.  
  133.  /*USE_OLDARGS*/
  134.  /*
  135.   * CAVEAT:  passing double (including float promoted to double) will
  136.   * almost certainly break this, as would any integer type bigger than
  137.   * sizeof (char *).
  138.   * NetHack avoids floating point, and any configuration able to use
  139.   * 'long long int' or I64P32 or the like should be using USE_STDARG.
  140.   */
  141.  #ifndef VA_TYPE
  142.  typedef const char *vA;
  143.  #define VA_TYPE
  144.  #endif
  145.  #define VA_ARGS arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9
  146.  #define VA_DECL(typ1, var1)                                             \
  147.      (var1, VA_ARGS) typ1 var1; vA VA_ARGS;                              \
  148.      {
  149.  #define VA_DECL2(typ1, var1, typ2, var2)                                \
  150.      (var1, var2, VA_ARGS) typ1 var1; typ2 var2; vA VA_ARGS;             \
  151.      {
  152.  #define VA_START(x)
  153.  #define VA_INIT(var1, typ1)
  154.  /* This is inherently risky, and should only be attempted as a
  155.     very last resort; manipulating arguments which haven't actually
  156.     been passed may or may not cause severe trouble depending on
  157.     the function-calling/argument-passing mechanism being used.
  158.  
  159.     [nethack's core doesn't use VA_NEXT() so doesn't use VA_SHIFT()
  160.     either, and this definition is just retained for completeness.
  161.     lev_comp does use VA_NEXT(), but it passes all 'argX' arguments.]
  162.   */
  163.  #define VA_SHIFT()                                                    \
  164.      (arg1 = arg2, arg2 = arg3, arg3 = arg4, arg4 = arg5, arg5 = arg6, \
  165.       arg6 = arg7, arg7 = arg8, arg8 = arg9, arg9 = 0)
  166.  #define VA_NEXT(var1, typ1) ((var1 = (typ1) arg1), VA_SHIFT(), var1)
  167.  #define VA_END() }
  168.  /* needed in pline.c, where full number of arguments is known and expected */
  169.  #define VA_PASS1(a1)                                                  \
  170.      (vA) a1, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0, (vA) 0
  171.  #endif
  172.  #endif
  173.  
  174.  #endif /* NEED_VARARGS */
  175.  
  176.  #if defined(NHSTDC) || defined(MSDOS) || defined(MAC) \
  177.      || defined(ULTRIX_PROTO) || defined(__BEOS__)
  178.  
  179.  /*
  180.   * Used for robust ANSI parameter forward declarations:
  181.   * int VDECL(sprintf, (char *, const char *, ...));
  182.   *
  183.   * NDECL() is used for functions with zero arguments;
  184.   * FDECL() is used for functions with a fixed number of arguments;
  185.   * VDECL() is used for functions with a variable number of arguments.
  186.   * Separate macros are needed because ANSI will mix old-style declarations
  187.   * with prototypes, except in the case of varargs, and the OVERLAY-specific
  188.   * trampoli.* mechanism conflicts with the ANSI <<f(void)>> syntax.
  189.   */
  190.  
  191.  #define NDECL(f) f(void) /* overridden later if USE_TRAMPOLI set */
  192.  
  193.  #define FDECL(f, p) f p
  194.  
  195.  #if defined(MSDOS) || defined(USE_STDARG)
  196.  #define VDECL(f, p) f p
  197.  #else
  198.  #define VDECL(f, p) f()
  199.  #endif
  200.  
  201.  /*
  202.   * Used for definitions of functions which take no arguments to force
  203.   * an explicit match with the NDECL prototype.  Needed in some cases
  204.   * (MS Visual C 2005) for functions called through pointers.
  205.   */
  206.  #define VOID_ARGS void
  207.  
  208.  /* generic pointer, always a macro; genericptr_t is usually a typedef */
  209.  #define genericptr void *
  210.  
  211.  #if (defined(ULTRIX_PROTO) && !defined(__GNUC__)) || defined(OS2_CSET2)
  212.  /* Cover for Ultrix on a DECstation with 2.0 compiler, which coredumps on
  213.   *   typedef void * genericptr_t;
  214.   *   extern void a(void(*)(int, genericptr_t));
  215.   * Using the #define is OK for other compiler versions too.
  216.   */
  217.  /* And IBM CSet/2.  The redeclaration of free hoses the compile. */
  218.  #define genericptr_t genericptr
  219.  #else
  220.  #if !defined(NHSTDC) && !defined(MAC)
  221.  #define const
  222.  #define signed
  223.  #define volatile
  224.  #endif
  225.  #endif
  226.  
  227.  /*
  228.   * Suppress `const' if necessary and not handled elsewhere.
  229.   * Don't use `#if defined(xxx) && !defined(const)'
  230.   * because some compilers choke on `defined(const)'.
  231.   * This has been observed with Lattice, MPW, and High C.
  232.   */
  233.  #if (defined(ULTRIX_PROTO) && !defined(NHSTDC)) || defined(apollo)
  234.  /* the system header files don't use `const' properly */
  235.  #ifndef const
  236.  #define const
  237.  #endif
  238.  #endif
  239.  
  240.  #else /* NHSTDC */ /* a "traditional" C  compiler */
  241.  
  242.  #define NDECL(f) f()
  243.  #define FDECL(f, p) f()
  244.  #define VDECL(f, p) f()
  245.  
  246.  #define VOID_ARGS /*empty*/
  247.  
  248.  #if defined(AMIGA) || defined(HPUX) || defined(POSIX_TYPES) \
  249.      || defined(__DECC) || defined(__BORLANDC__)
  250.  #define genericptr void *
  251.  #endif
  252.  #ifndef genericptr
  253.  #define genericptr char *
  254.  #endif
  255.  
  256.  /*
  257.   * Traditional C compilers don't have "signed", "const", or "volatile".
  258.   */
  259.  #define signed
  260.  #define const
  261.  #define volatile
  262.  
  263.  #endif /* NHSTDC */
  264.  
  265.  #ifndef genericptr_t
  266.  typedef genericptr genericptr_t; /* (void *) or (char *) */
  267.  #endif
  268.  
  269.  #if defined(MICRO) || defined(WIN32)
  270.  /* We actually want to know which systems have an ANSI run-time library
  271.   * to know which support the %p format for printing pointers.
  272.   * Due to the presence of things like gcc, NHSTDC is not a good test.
  273.   * So we assume microcomputers have all converted to ANSI and bigger
  274.   * computers which may have older libraries give reasonable results with
  275.   * casting pointers to unsigned long int (fmt_ptr() in alloc.c).
  276.   */
  277.  #define HAS_PTR_FMT
  278.  #endif
  279.  
  280.  /*
  281.   * According to ANSI, prototypes for old-style declarations must widen the
  282.   * arguments to int.  However, the MSDOS compilers accept shorter arguments
  283.   * (char, short, etc.) in prototypes and do typechecking with them.  Therefore
  284.   * this mess to allow the better typechecking while also allowing some
  285.   * prototypes for the ANSI compilers so people quit trying to fix the
  286.   * prototypes to match the standard and thus lose the typechecking.
  287.   */
  288.  #if defined(MSDOS) && !defined(__GO32__)
  289.  #define UNWIDENED_PROTOTYPES
  290.  #endif
  291.  #if defined(AMIGA) && !defined(AZTEC_50)
  292.  #define UNWIDENED_PROTOTYPES
  293.  #endif
  294.  #if defined(macintosh) && (defined(__SC__) || defined(__MRC__))
  295.  #define WIDENED_PROTOTYPES
  296.  #endif
  297.  #if defined(__MWERKS__) && defined(__BEOS__)
  298.  #define UNWIDENED_PROTOTYPES
  299.  #endif
  300.  #if defined(WIN32)
  301.  #define UNWIDENED_PROTOTYPES
  302.  #endif
  303.  
  304.  #if defined(ULTRIX_PROTO) && defined(ULTRIX_CC20)
  305.  #define UNWIDENED_PROTOTYPES
  306.  #endif
  307.  #if defined(apollo)
  308.  #define UNWIDENED_PROTOTYPES
  309.  #endif
  310.  
  311.  #ifndef UNWIDENED_PROTOTYPES
  312.  #if defined(NHSTDC) || defined(ULTRIX_PROTO) || defined(THINK_C)
  313.  #ifndef WIDENED_PROTOTYPES
  314.  #define WIDENED_PROTOTYPES
  315.  #endif
  316.  #endif
  317.  #endif
  318.  
  319.  /* These are used for arguments within FDECL/VDECL prototype declarations.
  320.   */
  321.  #ifdef UNWIDENED_PROTOTYPES
  322.  #define CHAR_P char
  323.  #define SCHAR_P schar
  324.  #define UCHAR_P uchar
  325.  #define XCHAR_P xchar
  326.  #define SHORT_P short
  327.  #ifndef SKIP_BOOLEAN
  328.  #define BOOLEAN_P boolean
  329.  #endif
  330.  #define ALIGNTYP_P aligntyp
  331.  #else
  332.  #ifdef WIDENED_PROTOTYPES
  333.  #define CHAR_P int
  334.  #define SCHAR_P int
  335.  #define UCHAR_P int
  336.  #define XCHAR_P int
  337.  #define SHORT_P int
  338.  #define BOOLEAN_P int
  339.  #define ALIGNTYP_P int
  340.  #else
  341.  /* Neither widened nor unwidened prototypes.  Argument list expansion
  342.   * by FDECL/VDECL always empty; all xxx_P vanish so defs aren't needed. */
  343.  #endif
  344.  #endif
  345.  
  346.  /* OBJ_P and MONST_P should _only_ be used for declaring function pointers.
  347.   */
  348.  #if defined(ULTRIX_PROTO) && !defined(__STDC__)
  349.  /* The ultrix 2.0 and 2.1 compilers (on Ultrix 4.0 and 4.2 respectively) can't
  350.   * handle "struct obj *" constructs in prototypes.  Their bugs are different,
  351.   * but both seem to work if we put "void*" in the prototype instead.  This
  352.   * gives us minimal prototype checking but avoids the compiler bugs.
  353.   */
  354.  #define OBJ_P void *
  355.  #define MONST_P void *
  356.  #else
  357.  #define OBJ_P struct obj *
  358.  #define MONST_P struct monst *
  359.  #endif
  360.  
  361.  #if 0
  362.  /* The problem below is still the case through 4.0.5F, but the suggested
  363.   * compiler flags in the Makefiles suppress the nasty messages, so we don't
  364.   * need to be quite so drastic.
  365.   */
  366.  #if defined(__sgi) && !defined(__GNUC__)
  367.  /*
  368.   * As of IRIX 4.0.1, /bin/cc claims to be an ANSI compiler, but it thinks
  369.   * it's impossible for a prototype to match an old-style definition with
  370.   * unwidened argument types.  Thus, we have to turn off all NetHack
  371.   * prototypes, and avoid declaring several system functions, since the system
  372.   * include files have prototypes and the compiler also complains that
  373.   * prototyped and unprototyped declarations don't match.
  374.   */
  375.  #undef NDECL
  376.  #undef FDECL
  377.  #undef VDECL
  378.  #define NDECL(f) f()
  379.  #define FDECL(f, p) f()
  380.  #define VDECL(f, p) f()
  381.  #undef VOID_ARGS
  382.  #define VOID_ARGS /*empty*/
  383.  #endif
  384.  #endif
  385.  
  386.  /* MetaWare High-C defaults to unsigned chars */
  387.  /* AIX 3.2 needs this also */
  388.  #if defined(__HC__) || defined(_AIX32)
  389.  #undef signed
  390.  #endif
  391.  
  392.  /*
  393.   * Allow gcc2 to check parameters of printf-like calls with -Wformat;
  394.   * append this to a prototype declaration (see pline() in extern.h).
  395.   */
  396.  #ifdef __GNUC__
  397.  #if (__GNUC__ >= 2) && !defined(USE_OLDARGS)
  398.  #define PRINTF_F(f, v) __attribute__((format(printf, f, v)))
  399.  #endif
  400.  #if __GNUC__ >= 3
  401.  #define UNUSED __attribute__((unused))
  402.  #define NORETURN __attribute__((noreturn))
  403.  #endif
  404.  #endif
  405.  
  406.  #ifndef PRINTF_F
  407.  #define PRINTF_F(f, v)
  408.  #endif
  409.  #ifndef UNUSED
  410.  #define UNUSED
  411.  #endif
  412.  #ifndef NORETURN
  413.  #define NORETURN
  414.  #endif
  415.  
  416.  #endif /* TRADSTDC_H */