* config/tc-ppc.h: Fix prototype declaration.
[binutils.git] / include / ansidecl.h
blobb7c4c40abff94dd8e69f92d2a976e2b1bef8eaa7
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.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 /* ANSI and traditional C compatibility macros
22 ANSI C is assumed if __STDC__ is #defined.
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)
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.
38 For declaring functions with prototypes, we also provide these:
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:
45 char *strcpy PARAMS ((char *dest, char *source));
46 ...
47 char *
48 strcpy (dest, source)
49 char *dest;
50 char *source;
51 { ... }
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:
58 int printf PARAMS ((const char *format, ...));
59 ...
60 int
61 printf VPARAMS ((const char *format, ...))
63 ...
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.
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.
78 Here is a complete example:
80 int
81 printf VPARAMS ((const char *format, ...))
83 int result;
85 VA_OPEN (ap, format);
86 VA_FIXEDARG (ap, const char *, format);
88 result = vfprintf (stdout, format, ap);
89 VA_CLOSE (ap);
91 return result;
95 You can declare variables either before or after the VA_OPEN,
96 VA_FIXEDARG sequence. You can _not_ put statements before VA_OPEN.
97 Also, VA_OPEN and VA_CLOSE are the beginning and end of a block.
98 They must appear at the same nesting level, and any variables
99 declared after VA_OPEN go out of scope at VA_CLOSE. Unfortunately,
100 with a K+R compiler, that includes the argument list.
102 For ease of writing code which uses GCC extensions but needs to be
103 portable to other compilers, we provide the GCC_VERSION macro that
104 simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
105 wrappers around __attribute__. Also, __extension__ will be #defined
106 to nothing if it doesn't work. See below.
108 This header also defines a lot of obsolete macros:
109 CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID,
110 AND, DOTS, NOARGS. Don't use them. */
112 #ifndef _ANSIDECL_H
113 #define _ANSIDECL_H 1
115 /* Every source file includes this file,
116 so they will all get the switch for lint. */
117 /* LINTLIBRARY */
119 /* Using MACRO(x,y) in cpp #if conditionals does not work with some
120 older preprocessors. Thus we can't define something like this:
122 #define HAVE_GCC_VERSION(MAJOR, MINOR) \
123 (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
125 and then test "#if HAVE_GCC_VERSION(2,7)".
127 So instead we use the macro below and test it against specific values. */
129 /* This macro simplifies testing whether we are using gcc, and if it
130 is of a particular minimum version. (Both major & minor numbers are
131 significant.) This macro will evaluate to 0 if we are not using
132 gcc at all. */
133 #ifndef GCC_VERSION
134 #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
135 #endif /* GCC_VERSION */
137 #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)
138 /* All known AIX compilers implement these things (but don't always
139 define __STDC__). The RISC/OS MIPS compiler defines these things
140 in SVR4 mode, but does not define __STDC__. */
142 #define ANSI_PROTOTYPES 1
143 #define PTR void *
144 #define PTRCONST void *const
145 #define LONG_DOUBLE long double
147 #define PARAMS(ARGS) ARGS
148 #define VPARAMS(ARGS) ARGS
149 #define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR)
151 /* variadic function helper macros */
152 /* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's
153 use without inhibiting further decls and without declaring an
154 actual variable. */
155 #define VA_OPEN(AP, VAR) va_list AP; va_start(AP, VAR); { struct Qdmy
156 #define VA_CLOSE(AP) } va_end(AP)
157 #define VA_FIXEDARG(AP, T, N) struct Qdmy
159 #undef const
160 #undef volatile
161 #undef signed
163 /* inline requires special treatment; it's in C99, and GCC >=2.7 supports
164 it too, but it's not in C89. */
165 #undef inline
166 #if __STDC_VERSION__ > 199901L
167 /* it's a keyword */
168 #else
169 # if GCC_VERSION >= 2007
170 # define inline __inline__ /* __inline__ prevents -pedantic warnings */
171 # else
172 # define inline /* nothing */
173 # endif
174 #endif
176 /* These are obsolete. Do not use. */
177 #ifndef IN_GCC
178 #define CONST const
179 #define VOLATILE volatile
180 #define SIGNED signed
182 #define PROTO(type, name, arglist) type name arglist
183 #define EXFUN(name, proto) name proto
184 #define DEFUN(name, arglist, args) name(args)
185 #define DEFUN_VOID(name) name(void)
186 #define AND ,
187 #define DOTS , ...
188 #define NOARGS void
189 #endif /* ! IN_GCC */
191 #else /* Not ANSI C. */
193 #undef ANSI_PROTOTYPES
194 #define PTR char *
195 #define PTRCONST PTR
196 #define LONG_DOUBLE double
198 #define PARAMS(args) ()
199 #define VPARAMS(args) (va_alist) va_dcl
200 #define VA_START(va_list, var) va_start(va_list)
202 #define VA_OPEN(AP, VAR) va_list AP; va_start(AP); { struct Qdmy
203 #define VA_CLOSE(AP) } va_end(AP)
204 #define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE)
206 /* some systems define these in header files for non-ansi mode */
207 #undef const
208 #undef volatile
209 #undef signed
210 #undef inline
211 #define const
212 #define volatile
213 #define signed
214 #define inline
216 #ifndef IN_GCC
217 #define CONST
218 #define VOLATILE
219 #define SIGNED
221 #define PROTO(type, name, arglist) type name ()
222 #define EXFUN(name, proto) name()
223 #define DEFUN(name, arglist, args) name arglist args;
224 #define DEFUN_VOID(name) name()
225 #define AND ;
226 #define DOTS
227 #define NOARGS
228 #endif /* ! IN_GCC */
230 #endif /* ANSI C. */
232 /* Define macros for some gcc attributes. This permits us to use the
233 macros freely, and know that they will come into play for the
234 version of gcc in which they are supported. */
236 #if (GCC_VERSION < 2007)
237 # define __attribute__(x)
238 #endif
240 /* Attribute __malloc__ on functions was valid as of gcc 2.96. */
241 #ifndef ATTRIBUTE_MALLOC
242 # if (GCC_VERSION >= 2096)
243 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
244 # else
245 # define ATTRIBUTE_MALLOC
246 # endif /* GNUC >= 2.96 */
247 #endif /* ATTRIBUTE_MALLOC */
249 /* Attributes on labels were valid as of gcc 2.93. */
250 #ifndef ATTRIBUTE_UNUSED_LABEL
251 # if (GCC_VERSION >= 2093)
252 # define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
253 # else
254 # define ATTRIBUTE_UNUSED_LABEL
255 # endif /* GNUC >= 2.93 */
256 #endif /* ATTRIBUTE_UNUSED_LABEL */
258 #ifndef ATTRIBUTE_UNUSED
259 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
260 #endif /* ATTRIBUTE_UNUSED */
262 #ifndef ATTRIBUTE_NORETURN
263 #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
264 #endif /* ATTRIBUTE_NORETURN */
266 #ifndef ATTRIBUTE_PRINTF
267 #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
268 #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
269 #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
270 #define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
271 #define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
272 #define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
273 #endif /* ATTRIBUTE_PRINTF */
275 /* We use __extension__ in some places to suppress -pedantic warnings
276 about GCC extensions. This feature didn't work properly before
277 gcc 2.8. */
278 #if GCC_VERSION < 2008
279 #define __extension__
280 #endif
282 /* Bootstrap support: Adjust certain macros defined by Autoconf,
283 which are only valid for the stage1 compiler. If we detect
284 a modern version of GCC, we are probably in stage2 or beyond,
285 so unconditionally reset the values. Note that const, inline,
286 etc. have been dealt with above. */
287 #if (GCC_VERSION >= 2007)
288 # ifndef HAVE_LONG_DOUBLE
289 # define HAVE_LONG_DOUBLE 1
290 # endif
291 #endif /* GCC >= 2.7 */
293 #endif /* ansidecl.h */