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