/* stdc.h -- JT standard C/C++ header file, cut-down for modern code only */ /* $Id$ */ /* * ***** THIS VERSION IS FOR ANSI/ISO C AND C++ ***** */ /* this header file is idempotent */ #ifndef STDC_H_SEEN #define STDC_H_SEEN /******************************************************************************/ /* * C/C++ compatability: */ /* use this in prototypes like this: extern C_FUNCTION void foo(...) */ #ifdef __cplusplus #define C_FUNCTION "C" #else #define C_FUNCTION /* empty */ #endif /******************************************************************************/ /* * New C/C++ "keywords" and types: */ #define then /* empty */ /* usage: if (foo) then bar; else baz; */ /* this makes "then" and "else" symmetrical */ /******************************************************************************/ /* * *** KLUDGE *** * * These macros suffer form the same "redefinition in system headers" * as my MIN/MAX macros (below). The fix here is the same as for MIN/MAX, * but this time conditional on linux: */ #ifndef FILENAME_MAX #if defined(LINUX) #define FILENAME_MAX 4095 #elif defined(ALPHA) /* gcc already defines this */ #else /* other systems */ #define FILENAME_MAX BUFSIZ #endif /* LINUX */ #endif /* printf(3) and scanf(3) formats and cast-types to print/read a pointer */ /* unfortunately, the ANSI/ISO C "%p" format isn't universal yet :-( */ /* even more unfortunately, ANSI/ISO printf() need not support length, */ /* precision, or indeed _any_ modifiers for the %p conversion */ #ifdef HAS_ISO_C_LIBRARY #define PRINTF_POINTER_FORMAT "%p" #define PRINTF_POINTER_TYPE void * #define SCANF_POINTER_FORMAT "%p" #define PRINTF_POINTER_TYPE void * #else #define PRINTF_POINTER_FORMAT "0x%08x" /* for 32-bit pointers */ #define PRINTF_POINTER_TYPE unsigned long #define SCANF_POINTER_FORMAT "0x%08x" /* for 32-bit pointers */ #define PRINTF_POINTER_TYPE unsigned long #endif /******************************************************************************/ #ifdef __cplusplus namespace jtutil { #endif /* * All my error handling is done with my error_exit() routine. It * prints an error message to stderr, then does an exit() or abort(). * It does *not* return to its caller. It's declared to return an * int , however, so it may be easily used in conditional expressions * like * foo = bar_ok ? baz(bar) : error_exit(...); */ extern C_FUNCTION int error_exit(int exit_code, const char *format, ...) #ifdef __GNUC__ __attribute__ ((noreturn)) __attribute__ ((format(printf,2,3))) #endif ; /* * error_exit() uses the following exit() codes: * OK_EXIT ==> everything's under control * ERROR_EXIT ==> something bad has happened * PANIC_EXIT ==> diasaster ==> force (eg) core dump, stack trace */ #ifdef VMS #define OK_EXIT 1 #define ERROR_EXIT 3 #define PANIC_EXIT (-1) #else #define OK_EXIT 0 #define ERROR_EXIT 1 #define PANIC_EXIT (-1) #endif #ifdef __cplusplus } /* close namespace jtutil */ using jtutil::error_exit; /* bring error_exit() into global namespace */ #endif /******************************************************************************/ #define iabs abs /* C library uses abs() for integer absolute value */ #define INT_SENTINAL_VALUE (~ INT_MAX) /* from */ /* usually 10...0 binary for */ /* a 2's complement system */ #define FLOAT_SENTINAL_VALUE (- FLT_MAX) /* from */ #define DOUBLE_SENTINAL_VALUE (- DBL_MAX) /* from */ /* misc integer sentinal value */ #define SENTINAL_VALUE INT_SENTINAL_VALUE /******************************************************************************/ #endif /* STDC_H_SEEN */