source: branches/libc-0.6/src/emx/include/ansidecl.h

Last change on this file was 1506, checked in by bird, 21 years ago

@unixroot. header reviews. ++

  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 9.4 KB
Line 
1/* ansidecl.h,v 1.2 2004/09/14 22:27:31 bird Exp */
2/** @file
3 * GNU, -liberty.
4 */
5
6/* ANSI and traditional C compatability macros
7 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
8 Free Software Foundation, Inc.
9 This file is part of the GNU C Library.
10
11This program is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2 of the License, or
14(at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24
25/* ANSI and traditional C compatibility macros
26
27 ANSI C is assumed if __STDC__ is #defined.
28
29 Macro ANSI C definition Traditional C definition
30 ----- ---- - ---------- ----------- - ----------
31 ANSI_PROTOTYPES 1 not defined
32 PTR `void *' `char *'
33 PTRCONST `void *const' `char *'
34 LONG_DOUBLE `long double' `double'
35 const not defined `'
36 volatile not defined `'
37 signed not defined `'
38 VA_START(ap, var) va_start(ap, var) va_start(ap)
39
40 Note that it is safe to write "void foo();" indicating a function
41 with no return value, in all K+R compilers we have been able to test.
42
43 For declaring functions with prototypes, we also provide these:
44
45 PARAMS ((prototype))
46 -- for functions which take a fixed number of arguments. Use this
47 when declaring the function. When defining the function, write a
48 K+R style argument list. For example:
49
50 char *strcpy PARAMS ((char *dest, char *source));
51 ...
52 char *
53 strcpy (dest, source)
54 char *dest;
55 char *source;
56 { ... }
57
58
59 VPARAMS ((prototype, ...))
60 -- for functions which take a variable number of arguments. Use
61 PARAMS to declare the function, VPARAMS to define it. For example:
62
63 int printf PARAMS ((const char *format, ...));
64 ...
65 int
66 printf VPARAMS ((const char *format, ...))
67 {
68 ...
69 }
70
71 For writing functions which take variable numbers of arguments, we
72 also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros. These
73 hide the differences between K+R <varargs.h> and C89 <stdarg.h> more
74 thoroughly than the simple VA_START() macro mentioned above.
75
76 VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end.
77 Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls
78 corresponding to the list of fixed arguments. Then use va_arg
79 normally to get the variable arguments, or pass your va_list object
80 around. You do not declare the va_list yourself; VA_OPEN does it
81 for you.
82
83 Here is a complete example:
84
85 int
86 printf VPARAMS ((const char *format, ...))
87 {
88 int result;
89
90 VA_OPEN (ap, format);
91 VA_FIXEDARG (ap, const char *, format);
92
93 result = vfprintf (stdout, format, ap);
94 VA_CLOSE (ap);
95
96 return result;
97 }
98
99
100 You can declare variables either before or after the VA_OPEN,
101 VA_FIXEDARG sequence. Also, VA_OPEN and VA_CLOSE are the beginning
102 and end of a block. They must appear at the same nesting level,
103 and any variables declared after VA_OPEN go out of scope at
104 VA_CLOSE. Unfortunately, with a K+R compiler, that includes the
105 argument list. You can have multiple instances of VA_OPEN/VA_CLOSE
106 pairs in a single function in case you need to traverse the
107 argument list more than once.
108
109 For ease of writing code which uses GCC extensions but needs to be
110 portable to other compilers, we provide the GCC_VERSION macro that
111 simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
112 wrappers around __attribute__. Also, __extension__ will be #defined
113 to nothing if it doesn't work. See below.
114
115 This header also defines a lot of obsolete macros:
116 CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID,
117 AND, DOTS, NOARGS. Don't use them. */
118
119#ifndef _ANSIDECL_H
120#define _ANSIDECL_H 1
121
122/* Every source file includes this file,
123 so they will all get the switch for lint. */
124/* LINTLIBRARY */
125
126/* Using MACRO(x,y) in cpp #if conditionals does not work with some
127 older preprocessors. Thus we can't define something like this:
128
129#define HAVE_GCC_VERSION(MAJOR, MINOR) \
130 (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
131
132and then test "#if HAVE_GCC_VERSION(2,7)".
133
134So instead we use the macro below and test it against specific values. */
135
136/* This macro simplifies testing whether we are using gcc, and if it
137 is of a particular minimum version. (Both major & minor numbers are
138 significant.) This macro will evaluate to 0 if we are not using
139 gcc at all. */
140#ifndef GCC_VERSION
141#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
142#endif /* GCC_VERSION */
143
144#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)
145/* All known AIX compilers implement these things (but don't always
146 define __STDC__). The RISC/OS MIPS compiler defines these things
147 in SVR4 mode, but does not define __STDC__. */
148
149#define ANSI_PROTOTYPES 1
150#define PTR void *
151#define PTRCONST void *const
152#define LONG_DOUBLE long double
153
154#define PARAMS(ARGS) ARGS
155#define VPARAMS(ARGS) ARGS
156#define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR)
157
158/* variadic function helper macros */
159/* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's
160 use without inhibiting further decls and without declaring an
161 actual variable. */
162#define VA_OPEN(AP, VAR) { va_list AP; va_start(AP, VAR); { struct Qdmy
163#define VA_CLOSE(AP) } va_end(AP); }
164#define VA_FIXEDARG(AP, T, N) struct Qdmy
165
166#undef const
167#undef volatile
168#undef signed
169
170/* inline requires special treatment; it's in C99, and GCC >=2.7 supports
171 it too, but it's not in C89. */
172#undef inline
173#if __STDC_VERSION__ > 199901L
174/* it's a keyword */
175#else
176# if GCC_VERSION >= 2007
177# define inline __inline__ /* __inline__ prevents -pedantic warnings */
178# else
179# define inline /* nothing */
180# endif
181#endif
182
183/* These are obsolete. Do not use. */
184#ifndef IN_GCC
185#define CONST const
186#define VOLATILE volatile
187#define SIGNED signed
188
189#define PROTO(type, name, arglist) type name arglist
190#define EXFUN(name, proto) name proto
191#define DEFUN(name, arglist, args) name(args)
192#define DEFUN_VOID(name) name(void)
193#define AND ,
194#define DOTS , ...
195#define NOARGS void
196#endif /* ! IN_GCC */
197
198#else /* Not ANSI C. */
199
200#undef ANSI_PROTOTYPES
201#define PTR char *
202#define PTRCONST PTR
203#define LONG_DOUBLE double
204
205#define PARAMS(args) ()
206#define VPARAMS(args) (va_alist) va_dcl
207#define VA_START(va_list, var) va_start(va_list)
208
209#define VA_OPEN(AP, VAR) { va_list AP; va_start(AP); { struct Qdmy
210#define VA_CLOSE(AP) } va_end(AP); }
211#define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE)
212
213/* some systems define these in header files for non-ansi mode */
214#undef const
215#undef volatile
216#undef signed
217#undef inline
218#define const
219#define volatile
220#define signed
221#define inline
222
223#ifndef IN_GCC
224#define CONST
225#define VOLATILE
226#define SIGNED
227
228#define PROTO(type, name, arglist) type name ()
229#define EXFUN(name, proto) name()
230#define DEFUN(name, arglist, args) name arglist args;
231#define DEFUN_VOID(name) name()
232#define AND ;
233#define DOTS
234#define NOARGS
235#endif /* ! IN_GCC */
236
237#endif /* ANSI C. */
238
239/* Define macros for some gcc attributes. This permits us to use the
240 macros freely, and know that they will come into play for the
241 version of gcc in which they are supported. */
242
243#if (GCC_VERSION < 2007)
244# define __attribute__(x)
245#endif
246
247/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
248#ifndef ATTRIBUTE_MALLOC
249# if (GCC_VERSION >= 2096)
250# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
251# else
252# define ATTRIBUTE_MALLOC
253# endif /* GNUC >= 2.96 */
254#endif /* ATTRIBUTE_MALLOC */
255
256/* Attributes on labels were valid as of gcc 2.93. */
257#ifndef ATTRIBUTE_UNUSED_LABEL
258# if (GCC_VERSION >= 2093)
259# define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
260# else
261# define ATTRIBUTE_UNUSED_LABEL
262# endif /* GNUC >= 2.93 */
263#endif /* ATTRIBUTE_UNUSED_LABEL */
264
265#ifndef ATTRIBUTE_UNUSED
266#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
267#endif /* ATTRIBUTE_UNUSED */
268
269#ifndef ATTRIBUTE_NORETURN
270#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
271#endif /* ATTRIBUTE_NORETURN */
272
273#ifndef ATTRIBUTE_PRINTF
274#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
275#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
276#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
277#define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
278#define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
279#define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
280#endif /* ATTRIBUTE_PRINTF */
281
282/* We use __extension__ in some places to suppress -pedantic warnings
283 about GCC extensions. This feature didn't work properly before
284 gcc 2.8. */
285#if GCC_VERSION < 2008
286#define __extension__
287#endif
288
289/* Bootstrap support: Adjust certain macros defined by Autoconf,
290 which are only valid for the stage1 compiler. If we detect
291 a modern version of GCC, we are probably in stage2 or beyond,
292 so unconditionally reset the values. Note that const, inline,
293 etc. have been dealt with above. */
294#if (GCC_VERSION >= 2007)
295# ifndef HAVE_LONG_DOUBLE
296# define HAVE_LONG_DOUBLE 1
297# endif
298#endif /* GCC >= 2.7 */
299
300#endif /* ansidecl.h */
Note: See TracBrowser for help on using the repository browser.