0
|
1 /* ANSI and traditional C compatability macros
|
|
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
|
|
3 Free Software Foundation, Inc.
|
|
4 This file is part of the GNU C Library.
|
|
5
|
|
6 This program is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 2 of the License, or
|
|
9 (at your option) any later version.
|
|
10
|
|
11 This program is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with this program; if not, write to the Free Software
|
|
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
|
|
19
|
|
20 /* ANSI and traditional C compatibility macros
|
|
21
|
|
22 ANSI C is assumed if __STDC__ is #defined.
|
|
23
|
|
24 Macro ANSI C definition Traditional C definition
|
|
25 ----- ---- - ---------- ----------- - ----------
|
|
26 ANSI_PROTOTYPES 1 not defined
|
|
27 PTR `void *' `char *'
|
|
28 PTRCONST `void *const' `char *'
|
|
29 LONG_DOUBLE `long double' `double'
|
|
30 const not defined `'
|
|
31 volatile not defined `'
|
|
32 signed not defined `'
|
|
33 VA_START(ap, var) va_start(ap, var) va_start(ap)
|
|
34
|
|
35 Note that it is safe to write "void foo();" indicating a function
|
|
36 with no return value, in all K+R compilers we have been able to test.
|
|
37
|
|
38 For declaring functions with prototypes, we also provide these:
|
|
39
|
|
40 PARAMS ((prototype))
|
|
41 -- for functions which take a fixed number of arguments. Use this
|
|
42 when declaring the function. When defining the function, write a
|
|
43 K+R style argument list. For example:
|
|
44
|
|
45 char *strcpy PARAMS ((char *dest, char *source));
|
|
46 ...
|
|
47 char *
|
|
48 strcpy (dest, source)
|
|
49 char *dest;
|
|
50 char *source;
|
|
51 { ... }
|
|
52
|
|
53
|
|
54 VPARAMS ((prototype, ...))
|
|
55 -- for functions which take a variable number of arguments. Use
|
|
56 PARAMS to declare the function, VPARAMS to define it. For example:
|
|
57
|
|
58 int printf PARAMS ((const char *format, ...));
|
|
59 ...
|
|
60 int
|
|
61 printf VPARAMS ((const char *format, ...))
|
|
62 {
|
|
63 ...
|
|
64 }
|
|
65
|
|
66 For writing functions which take variable numbers of arguments, we
|
|
67 also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros. These
|
|
68 hide the differences between K+R <varargs.h> and C89 <stdarg.h> more
|
|
69 thoroughly than the simple VA_START() macro mentioned above.
|
|
70
|
|
71 VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end.
|
|
72 Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls
|
|
73 corresponding to the list of fixed arguments. Then use va_arg
|
|
74 normally to get the variable arguments, or pass your va_list object
|
|
75 around. You do not declare the va_list yourself; VA_OPEN does it
|
|
76 for you.
|
|
77
|
|
78 Here is a complete example:
|
|
79
|
|
80 int
|
|
81 printf VPARAMS ((const char *format, ...))
|
|
82 {
|
|
83 int result;
|
|
84
|
|
85 VA_OPEN (ap, format);
|
|
86 VA_FIXEDARG (ap, const char *, format);
|
|
87
|
|
88 result = vfprintf (stdout, format, ap);
|
|
89 VA_CLOSE (ap);
|
|
90
|
|
91 return result;
|
|
92 }
|
|
93
|
|
94
|
|
95 You can declare variables either before or after the VA_OPEN,
|
|
96 VA_FIXEDARG sequence. Also, VA_OPEN and VA_CLOSE are the beginning
|
|
97 and end of a block. They must appear at the same nesting level,
|
|
98 and any variables declared after VA_OPEN go out of scope at
|
|
99 VA_CLOSE. Unfortunately, with a K+R compiler, that includes the
|
|
100 argument list. You can have multiple instances of VA_OPEN/VA_CLOSE
|
|
101 pairs in a single function in case you need to traverse the
|
|
102 argument list more than once.
|
|
103
|
|
104 For ease of writing code which uses GCC extensions but needs to be
|
|
105 portable to other compilers, we provide the GCC_VERSION macro that
|
|
106 simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
|
|
107 wrappers around __attribute__. Also, __extension__ will be #defined
|
|
108 to nothing if it doesn't work. See below.
|
|
109
|
|
110 This header also defines a lot of obsolete macros:
|
|
111 CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID,
|
|
112 AND, DOTS, NOARGS. Don't use them. */
|
|
113
|
|
114 #ifndef _ANSIDECL_H
|
|
115 #define _ANSIDECL_H 1
|
|
116
|
|
117 /* Every source file includes this file,
|
|
118 so they will all get the switch for lint. */
|
|
119 /* LINTLIBRARY */
|
|
120
|
|
121 /* Using MACRO(x,y) in cpp #if conditionals does not work with some
|
|
122 older preprocessors. Thus we can't define something like this:
|
|
123
|
|
124 #define HAVE_GCC_VERSION(MAJOR, MINOR) \
|
|
125 (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
|
|
126
|
|
127 and then test "#if HAVE_GCC_VERSION(2,7)".
|
|
128
|
|
129 So instead we use the macro below and test it against specific values. */
|
|
130
|
|
131 /* This macro simplifies testing whether we are using gcc, and if it
|
|
132 is of a particular minimum version. (Both major & minor numbers are
|
|
133 significant.) This macro will evaluate to 0 if we are not using
|
|
134 gcc at all. */
|
|
135 #ifndef GCC_VERSION
|
|
136 #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
|
|
137 #endif /* GCC_VERSION */
|
|
138
|
|
139 #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) || (defined(__alpha) && defined(__cplusplus))
|
|
140 /* All known AIX compilers implement these things (but don't always
|
|
141 define __STDC__). The RISC/OS MIPS compiler defines these things
|
|
142 in SVR4 mode, but does not define __STDC__. */
|
|
143 /* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
|
|
144 C++ compilers, does not define __STDC__, though it acts as if this
|
|
145 was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
|
|
146
|
|
147 #define ANSI_PROTOTYPES 1
|
|
148 #define PTR void *
|
|
149 #define PTRCONST void *const
|
|
150 #define LONG_DOUBLE long double
|
|
151
|
|
152 /* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in
|
|
153 a #ifndef. */
|
|
154 #ifndef PARAMS
|
|
155 #define PARAMS(ARGS) ARGS
|
|
156 #endif
|
|
157
|
|
158 #define VPARAMS(ARGS) ARGS
|
|
159 #define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR)
|
|
160
|
|
161 /* variadic function helper macros */
|
|
162 /* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's
|
|
163 use without inhibiting further decls and without declaring an
|
|
164 actual variable. */
|
|
165 #define VA_OPEN(AP, VAR) { va_list AP; va_start(AP, VAR); { struct Qdmy
|
|
166 #define VA_CLOSE(AP) } va_end(AP); }
|
|
167 #define VA_FIXEDARG(AP, T, N) struct Qdmy
|
|
168
|
|
169 #undef const
|
|
170 #undef volatile
|
|
171 #undef signed
|
|
172
|
|
173 /* inline requires special treatment; it's in C99, and GCC >=2.7 supports
|
|
174 it too, but it's not in C89. */
|
|
175 #undef inline
|
|
176 #if __STDC_VERSION__ > 199901L
|
|
177 /* it's a keyword */
|
|
178 #else
|
|
179 # if GCC_VERSION >= 2007
|
|
180 # define inline __inline__ /* __inline__ prevents -pedantic warnings */
|
|
181 # else
|
|
182 # define inline /* nothing */
|
|
183 # endif
|
|
184 #endif
|
|
185
|
|
186 /* These are obsolete. Do not use. */
|
|
187 #ifndef IN_GCC
|
|
188 #define CONST const
|
|
189 #define VOLATILE volatile
|
|
190 #define SIGNED signed
|
|
191
|
|
192 #define PROTO(type, name, arglist) type name arglist
|
|
193 #define EXFUN(name, proto) name proto
|
|
194 #define DEFUN(name, arglist, args) name(args)
|
|
195 #define DEFUN_VOID(name) name(void)
|
|
196 #define AND ,
|
|
197 #define DOTS , ...
|
|
198 #define NOARGS void
|
|
199 #endif /* ! IN_GCC */
|
|
200
|
|
201 #else /* Not ANSI C. */
|
|
202
|
|
203 #undef ANSI_PROTOTYPES
|
|
204 #define PTR char *
|
|
205 #define PTRCONST PTR
|
|
206 #define LONG_DOUBLE double
|
|
207
|
|
208 #define PARAMS(args) ()
|
|
209 #define VPARAMS(args) (va_alist) va_dcl
|
|
210 #define VA_START(va_list, var) va_start(va_list)
|
|
211
|
|
212 #define VA_OPEN(AP, VAR) { va_list AP; va_start(AP); { struct Qdmy
|
|
213 #define VA_CLOSE(AP) } va_end(AP); }
|
|
214 #define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE)
|
|
215
|
|
216 /* some systems define these in header files for non-ansi mode */
|
|
217 #undef const
|
|
218 #undef volatile
|
|
219 #undef signed
|
|
220 #undef inline
|
|
221 #define const
|
|
222 #define volatile
|
|
223 #define signed
|
|
224 #define inline
|
|
225
|
|
226 #ifndef IN_GCC
|
|
227 #define CONST
|
|
228 #define VOLATILE
|
|
229 #define SIGNED
|
|
230
|
|
231 #define PROTO(type, name, arglist) type name ()
|
|
232 #define EXFUN(name, proto) name()
|
|
233 #define DEFUN(name, arglist, args) name arglist args;
|
|
234 #define DEFUN_VOID(name) name()
|
|
235 #define AND ;
|
|
236 #define DOTS
|
|
237 #define NOARGS
|
|
238 #endif /* ! IN_GCC */
|
|
239
|
|
240 #endif /* ANSI C. */
|
|
241
|
|
242 /* Define macros for some gcc attributes. This permits us to use the
|
|
243 macros freely, and know that they will come into play for the
|
|
244 version of gcc in which they are supported. */
|
|
245
|
|
246 #if (GCC_VERSION < 2007)
|
|
247 # define __attribute__(x)
|
|
248 #endif
|
|
249
|
|
250 /* Attribute __malloc__ on functions was valid as of gcc 2.96. */
|
|
251 #ifndef ATTRIBUTE_MALLOC
|
|
252 # if (GCC_VERSION >= 2096)
|
|
253 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
|
|
254 # else
|
|
255 # define ATTRIBUTE_MALLOC
|
|
256 # endif /* GNUC >= 2.96 */
|
|
257 #endif /* ATTRIBUTE_MALLOC */
|
|
258
|
|
259 /* Attributes on labels were valid as of gcc 2.93. */
|
|
260 #ifndef ATTRIBUTE_UNUSED_LABEL
|
|
261 # if (!defined (__cplusplus) && GCC_VERSION >= 2093)
|
|
262 # define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
|
|
263 # else
|
|
264 # define ATTRIBUTE_UNUSED_LABEL
|
|
265 # endif /* !__cplusplus && GNUC >= 2.93 */
|
|
266 #endif /* ATTRIBUTE_UNUSED_LABEL */
|
|
267
|
|
268 #ifndef ATTRIBUTE_UNUSED
|
|
269 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
|
270 #endif /* ATTRIBUTE_UNUSED */
|
|
271
|
|
272 /* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
|
|
273 identifier name. */
|
|
274 #if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
|
|
275 # define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
|
|
276 #else /* !__cplusplus || GNUC >= 3.4 */
|
|
277 # define ARG_UNUSED(NAME) NAME
|
|
278 #endif /* !__cplusplus || GNUC >= 3.4 */
|
|
279
|
|
280 #ifndef ATTRIBUTE_NORETURN
|
|
281 #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
|
|
282 #endif /* ATTRIBUTE_NORETURN */
|
|
283
|
|
284 /* Attribute `nonnull' was valid as of gcc 3.3. */
|
|
285 #ifndef ATTRIBUTE_NONNULL
|
|
286 # if (GCC_VERSION >= 3003)
|
|
287 # define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
|
|
288 # else
|
|
289 # define ATTRIBUTE_NONNULL(m)
|
|
290 # endif /* GNUC >= 3.3 */
|
|
291 #endif /* ATTRIBUTE_NONNULL */
|
|
292
|
|
293 /* Attribute `pure' was valid as of gcc 3.0. */
|
|
294 #ifndef ATTRIBUTE_PURE
|
|
295 # if (GCC_VERSION >= 3000)
|
|
296 # define ATTRIBUTE_PURE __attribute__ ((__pure__))
|
|
297 # else
|
|
298 # define ATTRIBUTE_PURE
|
|
299 # endif /* GNUC >= 3.0 */
|
|
300 #endif /* ATTRIBUTE_PURE */
|
|
301
|
|
302 /* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
|
|
303 This was the case for the `printf' format attribute by itself
|
|
304 before GCC 3.3, but as of 3.3 we need to add the `nonnull'
|
|
305 attribute to retain this behavior. */
|
|
306 #ifndef ATTRIBUTE_PRINTF
|
|
307 #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
|
|
308 #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
|
|
309 #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
|
|
310 #define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
|
|
311 #define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
|
|
312 #define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
|
|
313 #endif /* ATTRIBUTE_PRINTF */
|
|
314
|
|
315 /* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on
|
|
316 a function pointer. Format attributes were allowed on function
|
|
317 pointers as of gcc 3.1. */
|
|
318 #ifndef ATTRIBUTE_FPTR_PRINTF
|
|
319 # if (GCC_VERSION >= 3001)
|
|
320 # define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n)
|
|
321 # else
|
|
322 # define ATTRIBUTE_FPTR_PRINTF(m, n)
|
|
323 # endif /* GNUC >= 3.1 */
|
|
324 # define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2)
|
|
325 # define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3)
|
|
326 # define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4)
|
|
327 # define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5)
|
|
328 # define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6)
|
|
329 #endif /* ATTRIBUTE_FPTR_PRINTF */
|
|
330
|
|
331 /* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A
|
|
332 NULL format specifier was allowed as of gcc 3.3. */
|
|
333 #ifndef ATTRIBUTE_NULL_PRINTF
|
|
334 # if (GCC_VERSION >= 3003)
|
|
335 # define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
|
|
336 # else
|
|
337 # define ATTRIBUTE_NULL_PRINTF(m, n)
|
|
338 # endif /* GNUC >= 3.3 */
|
|
339 # define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
|
|
340 # define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
|
|
341 # define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
|
|
342 # define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
|
|
343 # define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
|
|
344 #endif /* ATTRIBUTE_NULL_PRINTF */
|
|
345
|
|
346 /* Attribute `sentinel' was valid as of gcc 3.5. */
|
|
347 #ifndef ATTRIBUTE_SENTINEL
|
|
348 # if (GCC_VERSION >= 3005)
|
|
349 # define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
|
|
350 # else
|
|
351 # define ATTRIBUTE_SENTINEL
|
|
352 # endif /* GNUC >= 3.5 */
|
|
353 #endif /* ATTRIBUTE_SENTINEL */
|
|
354
|
|
355
|
|
356 #ifndef ATTRIBUTE_ALIGNED_ALIGNOF
|
|
357 # if (GCC_VERSION >= 3000)
|
|
358 # define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m))))
|
|
359 # else
|
|
360 # define ATTRIBUTE_ALIGNED_ALIGNOF(m)
|
|
361 # endif /* GNUC >= 3.0 */
|
|
362 #endif /* ATTRIBUTE_ALIGNED_ALIGNOF */
|
|
363
|
|
364 /* Useful for structures whose layout must much some binary specification
|
|
365 regardless of the alignment and padding qualities of the compiler. */
|
|
366 #ifndef ATTRIBUTE_PACKED
|
|
367 # define ATTRIBUTE_PACKED __attribute__ ((packed))
|
|
368 #endif
|
|
369
|
|
370 /* Attribute `hot' and `cold' was valid as of gcc 4.3. */
|
|
371 #ifndef ATTRIBUTE_COLD
|
|
372 # if (GCC_VERSION >= 4003)
|
|
373 # define ATTRIBUTE_COLD __attribute__ ((__cold__))
|
|
374 # else
|
|
375 # define ATTRIBUTE_COLD
|
|
376 # endif /* GNUC >= 4.3 */
|
|
377 #endif /* ATTRIBUTE_COLD */
|
|
378 #ifndef ATTRIBUTE_HOT
|
|
379 # if (GCC_VERSION >= 4003)
|
|
380 # define ATTRIBUTE_HOT __attribute__ ((__hot__))
|
|
381 # else
|
|
382 # define ATTRIBUTE_HOT
|
|
383 # endif /* GNUC >= 4.3 */
|
|
384 #endif /* ATTRIBUTE_HOT */
|
|
385
|
|
386 /* We use __extension__ in some places to suppress -pedantic warnings
|
|
387 about GCC extensions. This feature didn't work properly before
|
|
388 gcc 2.8. */
|
|
389 #if GCC_VERSION < 2008
|
|
390 #define __extension__
|
|
391 #endif
|
|
392
|
|
393 #endif /* ansidecl.h */
|