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
RevLine 
[1506]1/* ansidecl.h,v 1.2 2004/09/14 22:27:31 bird Exp */
2/** @file
3 * GNU, -liberty.
4 */
5
[123]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