source: trunk/src/emx/include/ansidecl.h@ 1940

Last change on this file since 1940 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