Changeset 609 for branches/GNU/src/binutils/include/ansidecl.h
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/include/ansidecl.h
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* ANSI and traditional C compatability macros 2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000 2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 3 3 Free Software Foundation, Inc. 4 4 This file is part of the GNU C Library. … … 22 22 ANSI C is assumed if __STDC__ is #defined. 23 23 24 Macro ANSI C definition Traditional C definition 25 ----- ---- - ---------- ----------- - ---------- 26 PTR `void *' `char *' 27 LONG_DOUBLE `long double' `double' 28 VOLATILE `volatile' `' 29 SIGNED `signed' `' 30 PTRCONST `void *const' `char *' 31 ANSI_PROTOTYPES 1 not defined 32 33 CONST is also defined, but is obsolete. Just use const. 34 35 obsolete -- DEFUN (name, arglist, args) 36 37 Defines function NAME. 38 39 ARGLIST lists the arguments, separated by commas and enclosed in 40 parentheses. ARGLIST becomes the argument list in traditional C. 41 42 ARGS list the arguments with their types. It becomes a prototype in 43 ANSI C, and the type declarations in traditional C. Arguments should 44 be separated with `AND'. For functions with a variable number of 45 arguments, the last thing listed should be `DOTS'. 46 47 obsolete -- DEFUN_VOID (name) 48 49 Defines a function NAME, which takes no arguments. 50 51 obsolete -- EXFUN (name, (prototype)) -- obsolete. 52 53 Replaced by PARAMS. Do not use; will disappear someday soon. 54 Was used in external function declarations. 55 In ANSI C it is `NAME PROTOTYPE' (so PROTOTYPE should be enclosed in 56 parentheses). In traditional C it is `NAME()'. 57 For a function that takes no arguments, PROTOTYPE should be `(void)'. 58 59 obsolete -- PROTO (type, name, (prototype) -- obsolete. 60 61 This one has also been replaced by PARAMS. Do not use. 62 63 PARAMS ((args)) 64 65 We could use the EXFUN macro to handle prototype declarations, but 66 the name is misleading and the result is ugly. So we just define a 67 simple macro to handle the parameter lists, as in: 68 69 static int foo PARAMS ((int, char)); 70 71 This produces: `static int foo();' or `static int foo (int, char);' 72 73 EXFUN would have done it like this: 74 75 static int EXFUN (foo, (int, char)); 76 77 but the function is not external...and it's hard to visually parse 78 the function name out of the mess. EXFUN should be considered 79 obsolete; new code should be written to use PARAMS. 80 81 DOTS is also obsolete. 82 83 Examples: 84 85 extern int printf PARAMS ((const char *format, ...)); 86 */ 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. */ 87 113 88 114 #ifndef _ANSIDECL_H 89 90 #define _ANSIDECL_H 1 91 115 #define _ANSIDECL_H 1 92 116 93 117 /* Every source file includes this file, 94 118 so they will all get the switch for lint. */ 95 119 /* LINTLIBRARY */ 96 97 98 #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)99 /* All known AIX compilers implement these things (but don't always100 define __STDC__). The RISC/OS MIPS compiler defines these things101 in SVR4 mode, but does not define __STDC__. */102 103 #define PTR void *104 #define PTRCONST void *CONST105 #define LONG_DOUBLE long double106 107 #ifndef IN_GCC108 #define AND ,109 #define NOARGS void110 #define VOLATILE volatile111 #define SIGNED signed112 #endif /* ! IN_GCC */113 114 #define PARAMS(paramlist) paramlist115 #define ANSI_PROTOTYPES 1116 117 #define VPARAMS(ARGS) ARGS118 #define VA_START(va_list,var) va_start(va_list,var)119 120 /* These are obsolete. Do not use. */121 #ifndef IN_GCC122 #define CONST const123 #define DOTS , ...124 #define PROTO(type, name, arglist) type name arglist125 #define EXFUN(name, proto) name proto126 #define DEFUN(name, arglist, args) name(args)127 #define DEFUN_VOID(name) name(void)128 #endif /* ! IN_GCC */129 130 #else /* Not ANSI C. */131 132 #define PTR char *133 #define PTRCONST PTR134 #define LONG_DOUBLE double135 136 #ifndef IN_GCC137 #define AND ;138 #define NOARGS139 #define VOLATILE140 #define SIGNED141 #endif /* !IN_GCC */142 143 #ifndef const /* some systems define it in header files for non-ansi mode */144 #define const145 #endif146 147 #define PARAMS(paramlist) ()148 149 #define VPARAMS(ARGS) (va_alist) va_dcl150 #define VA_START(va_list,var) va_start(va_list)151 152 /* These are obsolete. Do not use. */153 #ifndef IN_GCC154 #define CONST155 #define DOTS156 #define PROTO(type, name, arglist) type name ()157 #define EXFUN(name, proto) name()158 #define DEFUN(name, arglist, args) name arglist args;159 #define DEFUN_VOID(name) name()160 #endif /* ! IN_GCC */161 162 #endif /* ANSI C. */163 164 120 165 121 /* Using MACRO(x,y) in cpp #if conditionals does not work with some … … 181 137 #endif /* GCC_VERSION */ 182 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 #define PARAMS(ARGS) ARGS 153 #define VPARAMS(ARGS) ARGS 154 #define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR) 155 156 /* variadic function helper macros */ 157 /* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's 158 use without inhibiting further decls and without declaring an 159 actual variable. */ 160 #define VA_OPEN(AP, VAR) { va_list AP; va_start(AP, VAR); { struct Qdmy 161 #define VA_CLOSE(AP) } va_end(AP); } 162 #define VA_FIXEDARG(AP, T, N) struct Qdmy 163 164 #undef const 165 #undef volatile 166 #undef signed 167 168 /* inline requires special treatment; it's in C99, and GCC >=2.7 supports 169 it too, but it's not in C89. */ 170 #undef inline 171 #if __STDC_VERSION__ > 199901L 172 /* it's a keyword */ 173 #else 174 # if GCC_VERSION >= 2007 175 # define inline __inline__ /* __inline__ prevents -pedantic warnings */ 176 # else 177 # define inline /* nothing */ 178 # endif 179 #endif 180 181 /* These are obsolete. Do not use. */ 182 #ifndef IN_GCC 183 #define CONST const 184 #define VOLATILE volatile 185 #define SIGNED signed 186 187 #define PROTO(type, name, arglist) type name arglist 188 #define EXFUN(name, proto) name proto 189 #define DEFUN(name, arglist, args) name(args) 190 #define DEFUN_VOID(name) name(void) 191 #define AND , 192 #define DOTS , ... 193 #define NOARGS void 194 #endif /* ! IN_GCC */ 195 196 #else /* Not ANSI C. */ 197 198 #undef ANSI_PROTOTYPES 199 #define PTR char * 200 #define PTRCONST PTR 201 #define LONG_DOUBLE double 202 203 #define PARAMS(args) () 204 #define VPARAMS(args) (va_alist) va_dcl 205 #define VA_START(va_list, var) va_start(va_list) 206 207 #define VA_OPEN(AP, VAR) { va_list AP; va_start(AP); { struct Qdmy 208 #define VA_CLOSE(AP) } va_end(AP); } 209 #define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE) 210 211 /* some systems define these in header files for non-ansi mode */ 212 #undef const 213 #undef volatile 214 #undef signed 215 #undef inline 216 #define const 217 #define volatile 218 #define signed 219 #define inline 220 221 #ifndef IN_GCC 222 #define CONST 223 #define VOLATILE 224 #define SIGNED 225 226 #define PROTO(type, name, arglist) type name () 227 #define EXFUN(name, proto) name() 228 #define DEFUN(name, arglist, args) name arglist args; 229 #define DEFUN_VOID(name) name() 230 #define AND ; 231 #define DOTS 232 #define NOARGS 233 #endif /* ! IN_GCC */ 234 235 #endif /* ANSI C. */ 236 183 237 /* Define macros for some gcc attributes. This permits us to use the 184 238 macros freely, and know that they will come into play for the … … 215 269 #endif /* ATTRIBUTE_NORETURN */ 216 270 271 /* Attribute `nonnull' was valid as of gcc 3.3. */ 272 #ifndef ATTRIBUTE_NONNULL 273 # if (GCC_VERSION >= 3003) 274 # define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m))) 275 # else 276 # define ATTRIBUTE_NONNULL(m) 277 # endif /* GNUC >= 3.3 */ 278 #endif /* ATTRIBUTE_NONNULL */ 279 280 /* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL. 281 This was the case for the `printf' format attribute by itself 282 before GCC 3.3, but as of 3.3 we need to add the `nonnull' 283 attribute to retain this behavior. */ 217 284 #ifndef ATTRIBUTE_PRINTF 218 #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) 285 #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m) 219 286 #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2) 220 287 #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3) … … 224 291 #endif /* ATTRIBUTE_PRINTF */ 225 292 293 /* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A 294 NULL format specifier was allowed as of gcc 3.3. */ 295 #ifndef ATTRIBUTE_NULL_PRINTF 296 # if (GCC_VERSION >= 3003) 297 # define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) 298 # else 299 # define ATTRIBUTE_NULL_PRINTF(m, n) 300 # endif /* GNUC >= 3.3 */ 301 # define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2) 302 # define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3) 303 # define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4) 304 # define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5) 305 # define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6) 306 #endif /* ATTRIBUTE_NULL_PRINTF */ 307 226 308 /* We use __extension__ in some places to suppress -pedantic warnings 227 309 about GCC extensions. This feature didn't work properly before … … 231 313 #endif 232 314 315 /* Bootstrap support: Adjust certain macros defined by Autoconf, 316 which are only valid for the stage1 compiler. If we detect 317 a modern version of GCC, we are probably in stage2 or beyond, 318 so unconditionally reset the values. Note that const, inline, 319 etc. have been dealt with above. */ 320 #if (GCC_VERSION >= 2007) 321 # ifndef HAVE_LONG_DOUBLE 322 # define HAVE_LONG_DOUBLE 1 323 # endif 324 #endif /* GCC >= 2.7 */ 325 233 326 #endif /* ansidecl.h */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.