tradstdc.h

Go to the documentation of this file.
00001 /*      SCCS Id: @(#)tradstdc.h 3.4     1993/05/30      */
00002 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
00003 /* NetHack may be freely redistributed.  See license for details. */
00004 
00005 #ifndef TRADSTDC_H
00006 #define TRADSTDC_H
00007 
00008 #if defined(DUMB) && !defined(NOVOID)
00009 #define NOVOID
00010 #endif
00011 
00012 #ifdef NOVOID
00013 #define void int
00014 #endif
00015 
00016 /*
00017  * Borland C provides enough ANSI C compatibility in its Borland C++
00018  * mode to warrant this.  But it does not set __STDC__ unless it compiles
00019  * in its ANSI keywords only mode, which prevents use of <dos.h> and
00020  * far pointer use.
00021  */
00022 #if (defined(__STDC__) || defined(__TURBOC__)) && !defined(NOTSTDC)
00023 #define NHSTDC
00024 #endif
00025 
00026 #if defined(ultrix) && defined(__STDC__) && !defined(__LANGUAGE_C)
00027 /* Ultrix seems to be in a constant state of flux.  This check attempts to
00028  * set up ansi compatibility if it wasn't set up correctly by the compiler.
00029  */
00030 #ifdef mips
00031 #define __mips mips
00032 #endif
00033 
00034 #ifdef LANGUAGE_C
00035 #define __LANGUAGE_C LANGUAGE_C
00036 #endif
00037 
00038 #endif
00039 
00040 /*
00041  * ANSI X3J11 detection.
00042  * Makes substitutes for compatibility with the old C standard.
00043  */
00044 
00045 /* Decide how to handle variable parameter lists:
00046  * USE_STDARG means use the ANSI <stdarg.h> facilities (only ANSI compilers
00047  * should do this, and only if the library supports it).
00048  * USE_VARARGS means use the <varargs.h> facilities.  Again, this should only
00049  * be done if the library supports it.  ANSI is *not* required for this.
00050  * Otherwise, the kludgy old methods are used.
00051  * The defaults are USE_STDARG for ANSI compilers, and USE_OLDARGS for
00052  * others.
00053  */
00054 
00055 /* #define USE_VARARGS */       /* use <varargs.h> instead of <stdarg.h> */
00056 /* #define USE_OLDARGS */       /* don't use any variable argument facilites */
00057 
00058 #if defined(apollo)             /* Apollos have stdarg(3) but not stdarg.h */
00059 # define USE_VARARGS
00060 #endif
00061 
00062 #if defined(NHSTDC) || defined(ULTRIX_PROTO) || defined(MAC)
00063 # if !defined(USE_VARARGS) && !defined(USE_OLDARGS) && !defined(USE_STDARG)
00064 #   define USE_STDARG
00065 # endif
00066 #endif
00067 
00068 #ifdef NEED_VARARGS             /* only define these if necessary */
00069 #ifdef USE_STDARG
00070 #include <stdarg.h>
00071 # define VA_DECL(typ1,var1)     (typ1 var1, ...) { va_list the_args;
00072 # define VA_DECL2(typ1,var1,typ2,var2)  \
00073         (typ1 var1, typ2 var2, ...) { va_list the_args;
00074 # define VA_INIT(var1,typ1)
00075 # define VA_NEXT(var1,typ1)     var1 = va_arg(the_args, typ1)
00076 # define VA_ARGS                the_args
00077 # define VA_START(x)            va_start(the_args, x)
00078 # define VA_END()               va_end(the_args)
00079 # if defined(ULTRIX_PROTO) && !defined(_VA_LIST_)
00080 #  define _VA_LIST_     /* prevents multiple def in stdio.h */
00081 # endif
00082 #else
00083 # ifdef USE_VARARGS
00084 #include <varargs.h>
00085 #  define VA_DECL(typ1,var1)    (va_alist) va_dcl {\
00086                 va_list the_args; typ1 var1;
00087 #  define VA_DECL2(typ1,var1,typ2,var2) (va_alist) va_dcl {\
00088                 va_list the_args; typ1 var1; typ2 var2;
00089 #  define VA_ARGS               the_args
00090 #  define VA_START(x)           va_start(the_args)
00091 #  define VA_INIT(var1,typ1)    var1 = va_arg(the_args, typ1)
00092 #  define VA_NEXT(var1,typ1)    var1 = va_arg(the_args,typ1)
00093 #  define VA_END()              va_end(the_args)
00094 # else
00095 #   define VA_ARGS      arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9
00096 #   define VA_DECL(typ1,var1)  (var1,VA_ARGS) typ1 var1; \
00097         char *arg1,*arg2,*arg3,*arg4,*arg5,*arg6,*arg7,*arg8,*arg9; {
00098 #   define VA_DECL2(typ1,var1,typ2,var2)  (var1,var2,VA_ARGS) \
00099         typ1 var1; typ2 var2;\
00100         char *arg1,*arg2,*arg3,*arg4,*arg5,*arg6,*arg7,*arg8,*arg9; {
00101 #   define VA_START(x)
00102 #   define VA_INIT(var1,typ1)
00103 #   define VA_END()
00104 # endif
00105 #endif
00106 #endif /* NEED_VARARGS */
00107 
00108 #if defined(NHSTDC) || defined(MSDOS) || defined(MAC) || defined(ULTRIX_PROTO) || defined(__BEOS__)
00109 
00110 /*
00111  * Used for robust ANSI parameter forward declarations:
00112  * int VDECL(sprintf, (char *, const char *, ...));
00113  *
00114  * NDECL() is used for functions with zero arguments;
00115  * FDECL() is used for functions with a fixed number of arguments;
00116  * VDECL() is used for functions with a variable number of arguments.
00117  * Separate macros are needed because ANSI will mix old-style declarations
00118  * with prototypes, except in the case of varargs, and the OVERLAY-specific
00119  * trampoli.* mechanism conflicts with the ANSI <<f(void)>> syntax.
00120  */
00121 
00122 # define NDECL(f)       f(void) /* overridden later if USE_TRAMPOLI set */
00123 
00124 # define FDECL(f,p)     f p
00125 
00126 # if defined(MSDOS) || defined(USE_STDARG)
00127 #  define VDECL(f,p)    f p
00128 # else
00129 #  define VDECL(f,p)    f()
00130 # endif
00131 
00132 /* generic pointer, always a macro; genericptr_t is usually a typedef */
00133 # define genericptr     void *
00134 
00135 # if (defined(ULTRIX_PROTO) && !defined(__GNUC__)) || defined(OS2_CSET2)
00136 /* Cover for Ultrix on a DECstation with 2.0 compiler, which coredumps on
00137  *   typedef void * genericptr_t;
00138  *   extern void a(void(*)(int, genericptr_t));
00139  * Using the #define is OK for other compiler versions too.
00140  */
00141 /* And IBM CSet/2.  The redeclaration of free hoses the compile. */
00142 #  define genericptr_t  genericptr
00143 # else
00144 #  if !defined(NHSTDC) && !defined(MAC)
00145 #   define const
00146 #   define signed
00147 #   define volatile
00148 #  endif
00149 # endif
00150 
00151 /*
00152  * Suppress `const' if necessary and not handled elsewhere.
00153  * Don't use `#if defined(xxx) && !defined(const)'
00154  * because some compilers choke on `defined(const)'.
00155  * This has been observed with Lattice, MPW, and High C.
00156  */
00157 # if (defined(ULTRIX_PROTO) && !defined(NHSTDC)) || defined(apollo)
00158         /* the system header files don't use `const' properly */
00159 #  ifndef const
00160 #   define const
00161 #  endif
00162 # endif
00163 
00164 #else /* NHSTDC */      /* a "traditional" C  compiler */
00165 
00166 # define NDECL(f)       f()
00167 # define FDECL(f,p)     f()
00168 # define VDECL(f,p)     f()
00169 
00170 # if defined(AMIGA) || defined(HPUX) || defined(POSIX_TYPES) || defined(__DECC) || defined(__BORLANDC__)
00171 #  define genericptr    void *
00172 # endif
00173 # ifndef genericptr
00174 #  define genericptr    char *
00175 # endif
00176 
00177 /*
00178  * Traditional C compilers don't have "signed", "const", or "volatile".
00179  */
00180 # define signed
00181 # define const
00182 # define volatile
00183 
00184 #endif /* NHSTDC */
00185 
00186 
00187 #ifndef genericptr_t
00188 typedef genericptr genericptr_t;        /* (void *) or (char *) */
00189 #endif
00190 
00191 
00192 /*
00193  * According to ANSI, prototypes for old-style declarations must widen the
00194  * arguments to int.  However, the MSDOS compilers accept shorter arguments
00195  * (char, short, etc.) in prototypes and do typechecking with them.  Therefore
00196  * this mess to allow the better typechecking while also allowing some
00197  * prototypes for the ANSI compilers so people quit trying to fix the
00198  * prototypes to match the standard and thus lose the typechecking.
00199  */
00200 #if defined(MSDOS) && !defined(__GO32__)
00201 #define UNWIDENED_PROTOTYPES
00202 #endif
00203 #if defined(AMIGA) && !defined(AZTEC_50)
00204 #define UNWIDENED_PROTOTYPES
00205 #endif
00206 #if defined(macintosh) && (defined(__SC__) || defined(__MRC__))
00207 #define WIDENED_PROTOTYPES
00208 #endif
00209 #if defined(__MWERKS__) && defined(__BEOS__)
00210 #define UNWIDENED_PROTOTYPES
00211 #endif
00212 #if defined(WIN32)
00213 #define UNWIDENED_PROTOTYPES
00214 #endif
00215 
00216 #if defined(ULTRIX_PROTO) && defined(ULTRIX_CC20)
00217 #define UNWIDENED_PROTOTYPES
00218 #endif
00219 #if defined(apollo)
00220 #define UNWIDENED_PROTOTYPES
00221 #endif
00222 
00223 #ifndef UNWIDENED_PROTOTYPES
00224 # if defined(NHSTDC) || defined(ULTRIX_PROTO) || defined(THINK_C)
00225 # define WIDENED_PROTOTYPES
00226 # endif
00227 #endif
00228 
00229 #if 0
00230 /* The problem below is still the case through 4.0.5F, but the suggested
00231  * compiler flags in the Makefiles suppress the nasty messages, so we don't
00232  * need to be quite so drastic.
00233  */
00234 #if defined(__sgi) && !defined(__GNUC__)
00235 /*
00236  * As of IRIX 4.0.1, /bin/cc claims to be an ANSI compiler, but it thinks
00237  * it's impossible for a prototype to match an old-style definition with
00238  * unwidened argument types.  Thus, we have to turn off all NetHack
00239  * prototypes, and avoid declaring several system functions, since the system
00240  * include files have prototypes and the compiler also complains that
00241  * prototyped and unprototyped declarations don't match.
00242  */
00243 # undef NDECL
00244 # undef FDECL
00245 # undef VDECL
00246 # define NDECL(f)       f()
00247 # define FDECL(f,p)     f()
00248 # define VDECL(f,p)     f()
00249 #endif
00250 #endif
00251 
00252 
00253         /* MetaWare High-C defaults to unsigned chars */
00254         /* AIX 3.2 needs this also */
00255 #if defined(__HC__) || defined(_AIX32)
00256 # undef signed
00257 #endif
00258 
00259 
00260 /*
00261  * Allow gcc2 to check parameters of printf-like calls with -Wformat;
00262  * append this to a prototype declaration (see pline() in extern.h).
00263  */
00264 #ifdef __GNUC__
00265 # if __GNUC__ >= 2
00266 #define PRINTF_F(f,v) __attribute__ ((format (printf, f, v)))
00267 # endif
00268 #endif
00269 #ifndef PRINTF_F
00270 #define PRINTF_F(f,v)
00271 #endif
00272 
00273 #endif /* TRADSTDC_H */