]> pd.if.org Git - pdclib/blob - _PDCLIB_config.h
2b69f07c121805e1a2c3d85ed8d7d95029e595c1
[pdclib] / _PDCLIB_config.h
1 /* $Id$ */
2
3 /* Release: $Name$ */
4
5 /* Internal PDCLib configuration <_PDCLIB_config.h>
6    (Generic Template)
7
8    This file is part of the Public Domain C Library (PDCLib).
9    Permission is granted to use, modify, and / or redistribute at will.
10 */
11
12 /* -------------------------------------------------------------------------- */
13 /* Integers                                                                   */
14 /* -------------------------------------------------------------------------- */
15 /* Assuming 8-bit char, two's-complement architecture here. 'short' being     */
16 /* either 8 or 16 bit, 'int' being either 16, 32 or 64 bit, 'long' being      */
17 /* either 32 or 64 bit, and 'long long' being 64 bit if 'long' is not, 64 or  */
18 /* 128 bit otherwise.                                                         */
19 /* Author is quite willing to support other systems but would like to hear of */
20 /* interest in such support and details on the to-be-supported architecture   */
21 /* first before going to lengths about it.                                    */
22 /* -------------------------------------------------------------------------- */
23
24 /* Comment out (or delete) the line below if your 'char' type is unsigned.    */
25 #define _PDCLIB_CHAR_SIGNED _PDCLIB_CHAR_SIGNED
26
27 /* Width of the integer types short, int, long, and long long, in bytes.      */
28 #define _PDCLIB_SHRT_BYTES  2
29 #define _PDCLIB_INT_BYTES   4
30 #define _PDCLIB_LONG_BYTES  4
31 #define _PDCLIB_LLONG_BYTES 8
32
33 /* -------------------------------------------------------------------------- */
34 /* <stdint.h> defines a set of integer types that are of a minimum width, and */
35 /* "usually fastest" on the system. (If, for example, accessing a single char */
36 /* requires the CPU to access a complete int and then mask out the char, the  */
37 /* "usually fastest" type of at least 8 bits would be int, not char.)         */
38 /* If you do not have information on the relative performance of the types,   */
39 /* the standard allows you to define any type that meets minimum width and    */
40 /* signedness requirements.                                                   */
41 /* The defines below are just configuration for the real typedefs and limit   */
42 /* definitions done in <_PDCLIB_int.h>. The uppercase define shall be either  */
43 /* SHRT, INT, LONG, or LLONG (telling which values to use for the *_MIN and   */
44 /* *_MAX limits); the lowercase define either short, int, long, or long long  */
45 /* (telling the actual type to use).                                          */
46 /* If you require a non-standard datatype to define the "usually fastest"     */
47 /* types, PDCLib as-is doesn't support that. Please contact the author with   */
48 /* details on your platform in that case, so support can be added.            */
49 /* -------------------------------------------------------------------------- */
50
51 #define _PDCLIB_FAST8 INT
52 #define _PDCLIB_fast8 int
53
54 #define _PDCLIB_FAST16 INT
55 #define _PDCLIB_fast16 int
56
57 #define _PDCLIB_FAST32 INT
58 #define _PDCLIB_fast32 int
59
60 #define _PDCLIB_FAST64 LLONG
61 #define _PDCLIB_fast64 long long
62
63 /* -------------------------------------------------------------------------- */
64 /* What follows are a couple of "special" typedefs and their limits. Again,   */
65 /* the actual definition of the limits is done in <_PDCLIB_int.h>, and the    */
66 /* defines here are merely "configuration".                                   */
67 /* Type is defined directly, limits are defined the same way as the "fastest" */
68 /* limits above (SHRT, USHRT, INT, UINT, LONG, ULONG, LLONG, or ULLONG).      */
69 /* -------------------------------------------------------------------------- */
70
71 /* The result type of substracting two pointers */
72 typedef int             _PDCLIB_ptrdiff_t;
73 #define _PDCLIB_PTRDIFF INT
74
75 /* An integer type that can be accessed as atomic entity (think asynchronous
76    interrupts). The type itself is not defined in a freestanding environment,
77    but its limits are. (Don't ask.)
78 */
79 #define _PDCLIB_SIG_ATOMIC INT
80
81 /* Result type of the 'sizeof' operator */
82 typedef unsigned int _PDCLIB_size_t;
83 #define _PDCLIB_SIZE UINT
84
85 /* Large enough an integer to hold all character codes of the largest supported
86    locale.
87 */
88 #define _PDCLIB_WCHAR  USHRT
89 typedef unsigned short _PDCLIB_wchar_t;
90
91 /* -------------------------------------------------------------------------- */
92 /* Floating Point                                                             */
93 /* -------------------------------------------------------------------------- */
94
95 /* Whether the implementation rounds toward zero (0), to nearest (1), toward
96    positive infinity (2), or toward negative infinity (3). (-1) signifies
97    indeterminable rounding, any other value implementation-specific rounding.
98 */
99 #define _PDCLIB_FLT_ROUNDS -1
100
101 /* Whether the implementation uses exact-width precision (0), promotes float
102    to double (1), or promotes float and double to long double (2). (-1)
103    signifies indeterminable behaviour, any other value implementation-specific
104    behaviour.
105 */
106 #define _PDCLIB_FLT_EVAL_METHOD -1
107
108 /* "Number of the decimal digits (n), such that any floating-point number in the
109    widest supported floating type with p(max) radix (b) digits can be rounded to
110    a floating-point number with (n) decimal digits and back again without change
111    to the value p(max) log(10)b if (b) is a power of 10, [1 + p(max) log(10)b]
112    otherwise."
113    64bit IEC 60559 double format (53bit mantissa) is DECIMAL_DIG 17.
114    80bit IEC 60559 double-extended format (64bit mantissa) is DECIMAL_DIG 21.
115 */
116 #define _PDCLIB_DECIMAL_DIG 17
117
118 /* -------------------------------------------------------------------------- */
119 /* Platform-dependent macros defined by the standard headers.                 */
120 /* -------------------------------------------------------------------------- */
121
122 /* The offsetof macro
123    Contract: Expand to an integer constant expression of type size_t, which
124    represents the offset in bytes to the structure member from the beginning
125    of the structure. If the specified member is a bitfield, behaviour is
126    undefined.
127    There is no standard-compliant way to do this.
128    This implementation casts an integer zero to 'pointer to type', and then
129    takes the address of member. This is undefined behaviour but should work on
130    most compilers.
131 */
132 #define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) )
133
134 /* Variable Length Parameter List Handling (<stdarg.h>)
135    The macros defined by <stdarg.h> are highly dependent on the calling
136    conventions used, and you probably have to replace them with builtins of
137    your compiler. The following generic implementation works only for pure
138    stack-based architectures, and only if arguments are aligned to pointer
139    type. Credits to Michael Moody, who contributed this to the Public Domain.
140 */
141
142 /* Internal helper macro. va_round is not part of <stdarg.h>. */
143 #define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) )
144
145 typedef char * _PDCLIB_va_list;
146 #define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) )
147 #define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 )
148 #define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 )
149 #define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 )