aboutsummaryrefslogtreecommitdiff
path: root/src/include/stdc.h
blob: a3a929e8a559b6ba35ffa683d7b899263a045831 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* 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

/******************************************************************************/

/*
 * I use this empty macro in all if statements -- I like the symmetry
 * between the two branches of an if statement.
 *
 *	if (foo)
 *	   then bar;
 *
 *	if (foo)
 *	   then bar;
 *	   else baz;
 */
#define then	/* empty */

/******************************************************************************/

/*
 * misc stuff
 */

#ifdef M_PI		/* usually defined in <math.h> */
  #define PI	M_PI
#endif

#define STRING_EQUAL(s_,t_)	(strcmp(s_,t_) == 0)

/* C library uses abs() for integer absolute value; I prefer iabs() */
#define iabs(x_)	abs(x_)

/******************************************************************************/

/*
 * misc sentinal values
 */

/* n.b. this value is usually 10...0 binary for 2's-complement arithmetic */
#define INT_SENTINAL_VALUE	(~ INT_MAX)	/* from <limits.h> */

#define FLOAT_SENTINAL_VALUE	(- FLT_MAX)	/* from <float.h> */
#define DOUBLE_SENTINAL_VALUE	(- DBL_MAX)	/* from <float.h> */

/******************************************************************************/

#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(...);
 */
#ifdef __cplusplus
  extern "C"
#endif
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
	  }	/* namespace jtutil */
#endif

/******************************************************************************/

#endif	/* STDC_H_SEEN */