check if the compiler supports -funroll-loops
[AROS.git] / test / sdi / SDI_stdarg.h
blobe29f9ca6bd34d4ff48ca114ecfd36bdc92c4ea99
1 #ifndef SDI_STDARG_H
2 #define SDI_STDARG_H
4 /* Includeheader
6 Name: SDI_stdarg.h
7 Versionstring: $VER: SDI_stdarg.h 1.3 (06.08.2016)
8 Author: Jens Maus
9 Distribution: PD
10 Project page: https://github.com/adtools/SDI
11 Description: defines to hide OS specific variable arguments
12 function definitions
14 1.0 05.07.2004 : initial version
15 1.1 06.06.2014 : added a type cast to VA_ARG() result
16 1.2 27.03.2016 : when using GCC4/5 for MorphOS overflow_arg_area is not
17 supported anymore (Jens Maus)
18 1.3 06.08.2016 : implemented VA_COPY() and SDI_VACAST type helper macros
19 to fight the problem that GCC5 for MorphOS doesn't support
20 VARARGS68K and thus we need type casts to please the
21 compiler on complaining about the GCC inline macros that
22 can be used to partly replace it.
27 ** This is PD (Public Domain). This means you can do with it whatever you want
28 ** without any restrictions. I only ask you to tell me improvements, so I may
29 ** fix the main line of this files as well.
31 ** To keep confusion level low: When changing this file, please note it in
32 ** above history list and indicate that the change was not made by myself
33 ** (e.g. add your name or nick name).
35 ** Find the latest version of this file at:
36 ** https://github.com/adtools/SDI
38 ** Jens Maus <mail@jens-maus.de>
39 ** Dirk Stöcker <soft@dstoecker.de>
42 #include "SDI_compiler.h"
45 ** Variable arguments function macros to allow specification of the
46 ** variable arguments typical functions like va_list/va_start/va_end in
47 ** an operating system independent fashion.
49 ** With help of the following macro definition a developer might define
50 ** variable arguments functions for different types of operating
51 ** system implementations without having to clutter the sources with
52 ** multiple "#ifdef" defines just because all of these operating systems
53 ** come with different varable arguments support functions.
55 ** Example:
57 ** Instead of using the standard va_list, va_start and va_end functions
58 ** of <stdarg.h>, a developer might specify the following sprintf()
59 ** function to make it automatically compatible with AmigaOS3, AmigaOS4
60 ** and also MorphOS.
62 ** int VARARGS68K sprintf(char *buf, char *fmt, ...)
63 ** {
64 ** VA_LIST args;
66 ** VA_START(args, fmt);
67 ** RawDoFmt(fmt, VA_ARG(args, void *), NULL, buf);
68 ** VA_END(args);
70 ** return(strlen(buf));
71 ** }
73 ** Please note the uppercase letters of the macros in contrast to the
74 ** official varargs functions specified in <stdarg.h>.
76 ** By using this schema a developer might ensure full source code backward
77 ** compatibility to AmigaOS3 without having to introduce dozens of #ifdef
78 ** statements in his code.
81 #include <stdarg.h>
83 #ifdef VA_LIST
84 #undef VA_LIST
85 #endif
86 #ifdef VA_START
87 #undef VA_START
88 #endif
89 #ifdef VA_ARG
90 #undef VA_ARG
91 #endif
92 #ifdef VA_END
93 #undef VA_END
94 #endif
96 #if defined(__amigaos4__)
97 #define VA_LIST va_list
98 #define VA_START(va, start) va_startlinear((va), (start))
99 #define VA_ARG(va, type) va_getlinearva((va), type)
100 #define VA_COPY(d, s) (d) = (s)
101 #define VA_END(va) va_end((va))
102 #elif defined(__MORPHOS__)
103 #define VA_LIST va_list
104 #define VA_START(va, start) va_start((va), (start))
105 #if __GNUC__ == 2
106 #define VA_ARG(va, type) (type)((va)->overflow_arg_area)
107 #else
108 #define VA_ARG(va, type) va_arg(va, type)
109 #endif
110 #define VA_COPY(d, s) __va_copy(d, s)
111 #define VA_END(va) va_end((va))
112 #else
113 #define VA_LIST va_list
114 #define VA_START(va, start) va_start((va), (start))
115 #define VA_ARG(va, type) (type)(va)
116 #if defined(__AROS__)
117 #define VA_COPY(d, s) va_copy(d, s)
118 #else
119 #define VA_COPY(d, s) (d) = (s)
120 #endif
121 #define VA_END(va) va_end((va))
122 #endif
124 /* This counts the number of args */
125 #define SDI_NARGS_SEQ( _1, _2, _3, _4, _5, _6, _7, _8, _9,_10,\
126 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20,\
127 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30,\
128 N,...) N
129 #define SDI_NARGS(...) SDI_NARGS_SEQ(__VA_ARGS__,\
130 30,29,28,27,26,25,24,23,22,21,\
131 20,19,18,17,16,15,14,13,12,11,\
132 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
134 /* This will let macros expand before concating them */
135 #define SDI_PRIMITIVE_CAT(x, y) x ## y
136 #define SDI_CAT(x, y) SDI_PRIMITIVE_CAT(x, y)
138 /* This will call a macro on each argument passed in */
139 #define SDI_VACAST(...) SDI_CAT(SDI_CAST_, SDI_NARGS(__VA_ARGS__))((ULONG), __VA_ARGS__)
140 #define SDI_CAST_1(m,x1) m(x1)
141 #define SDI_CAST_2(m,x1,x2) m(x1),m(x2)
142 #define SDI_CAST_3(m,x1,x2,x3) m(x1),m(x2),m(x3)
143 #define SDI_CAST_4(m,x1,x2,x3,x4) m(x1),m(x2),m(x3),m(x4)
144 #define SDI_CAST_5(m,x1,x2,x3,x4,x5) m(x1),m(x2),m(x3),m(x4),m(x5)
145 #define SDI_CAST_6(m,x1,x2,x3,x4,x5,x6) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6)
146 #define SDI_CAST_7(m,x1,x2,x3,x4,x5,x6,x7) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7)
147 #define SDI_CAST_8(m,x1,x2,x3,x4,x5,x6,x7,x8) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8)
148 #define SDI_CAST_9(m,x1,x2,x3,x4,x5,x6,x7,x8,x9) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9)
149 #define SDI_CAST_10(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10)
150 #define SDI_CAST_11(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11)
151 #define SDI_CAST_12(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12)
152 #define SDI_CAST_13(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13)
153 #define SDI_CAST_14(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14)
154 #define SDI_CAST_15(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15)
155 #define SDI_CAST_16(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16)
156 #define SDI_CAST_17(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17)
157 #define SDI_CAST_18(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18)
158 #define SDI_CAST_19(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19)
159 #define SDI_CAST_20(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19),m(x20)
160 #define SDI_CAST_21(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19),m(x20),m(x21)
161 #define SDI_CAST_22(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19),m(x20),m(x21),m(x22)
162 #define SDI_CAST_23(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19),m(x20),m(x21),m(x22),m(x23)
163 #define SDI_CAST_24(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23,x24) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19),m(x20),m(x21),m(x22),m(x23),m(x24)
164 #define SDI_CAST_25(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23,x24,x25) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19),m(x20),m(x21),m(x22),m(x23),m(x24),m(x25)
165 #define SDI_CAST_26(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23,x24,x25,x26) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19),m(x20),m(x21),m(x22),m(x23),m(x24),m(x25),m(x26)
166 #define SDI_CAST_27(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23,x24,x25,x26,x27) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19),m(x20),m(x21),m(x22),m(x23),m(x24),m(x25),m(x26),m(x27)
167 #define SDI_CAST_28(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23,x24,x25,x26,x27,x28) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19),m(x20),m(x21),m(x22),m(x23),m(x24),m(x25),m(x26),m(x27),m(x28)
168 #define SDI_CAST_29(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23,x24,x25,x26,x27,x28,x29) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19),m(x20),m(x21),m(x22),m(x23),m(x24),m(x25),m(x26),m(x27),m(x28),m(x29)
169 #define SDI_CAST_30(m,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22,x23,x24,x25,x26,x27,x28,x29,x30) m(x1),m(x2),m(x3),m(x4),m(x5),m(x6),m(x7),m(x8),m(x9),m(x10),m(x11),m(x12),m(x13),m(x14),m(x15),m(x16),m(x17),m(x18),m(x19),m(x20),m(x21),m(x22),m(x23),m(x24),m(x25),m(x26),m(x27),m(x28),m(x29),m(x30)
171 #endif /* SDI_STDARG_H */