00001 /* 00002 * Copyright 2003, 2004, 2005, 2006 PathScale, Inc. All Rights Reserved. 00003 */ 00004 00005 /* ANSI and traditional C compatability macros 00006 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 00007 Free Software Foundation, Inc. 00008 This file is part of the GNU C Library. 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation; either version 2 of the License, or 00013 (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 00023 00024 /* ANSI and traditional C compatibility macros 00025 00026 ANSI C is assumed if __STDC__ is #defined. 00027 00028 Macro ANSI C definition Traditional C definition 00029 ----- ---- - ---------- ----------- - ---------- 00030 ANSI_PROTOTYPES 1 not defined 00031 PTR `void *' `char *' 00032 PTRCONST `void *const' `char *' 00033 LONG_DOUBLE `long double' `double' 00034 const not defined `' 00035 volatile not defined `' 00036 signed not defined `' 00037 VA_START(ap, var) va_start(ap, var) va_start(ap) 00038 00039 Note that it is safe to write "void foo();" indicating a function 00040 with no return value, in all K+R compilers we have been able to test. 00041 00042 For declaring functions with prototypes, we also provide these: 00043 00044 PARAMS ((prototype)) 00045 -- for functions which take a fixed number of arguments. Use this 00046 when declaring the function. When defining the function, write a 00047 K+R style argument list. For example: 00048 00049 char *strcpy PARAMS ((char *dest, char *source)); 00050 ... 00051 char * 00052 strcpy (dest, source) 00053 char *dest; 00054 char *source; 00055 { ... } 00056 00057 00058 VPARAMS ((prototype, ...)) 00059 -- for functions which take a variable number of arguments. Use 00060 PARAMS to declare the function, VPARAMS to define it. For example: 00061 00062 int printf PARAMS ((const char *format, ...)); 00063 ... 00064 int 00065 printf VPARAMS ((const char *format, ...)) 00066 { 00067 ... 00068 } 00069 00070 For writing functions which take variable numbers of arguments, we 00071 also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros. These 00072 hide the differences between K+R <varargs.h> and C89 <stdarg.h> more 00073 thoroughly than the simple VA_START() macro mentioned above. 00074 00075 VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end. 00076 Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls 00077 corresponding to the list of fixed arguments. Then use va_arg 00078 normally to get the variable arguments, or pass your va_list object 00079 around. You do not declare the va_list yourself; VA_OPEN does it 00080 for you. 00081 00082 Here is a complete example: 00083 00084 int 00085 printf VPARAMS ((const char *format, ...)) 00086 { 00087 int result; 00088 00089 VA_OPEN (ap, format); 00090 VA_FIXEDARG (ap, const char *, format); 00091 00092 result = vfprintf (stdout, format, ap); 00093 VA_CLOSE (ap); 00094 00095 return result; 00096 } 00097 00098 00099 You can declare variables either before or after the VA_OPEN, 00100 VA_FIXEDARG sequence. Also, VA_OPEN and VA_CLOSE are the beginning 00101 and end of a block. They must appear at the same nesting level, 00102 and any variables declared after VA_OPEN go out of scope at 00103 VA_CLOSE. Unfortunately, with a K+R compiler, that includes the 00104 argument list. You can have multiple instances of VA_OPEN/VA_CLOSE 00105 pairs in a single function in case you need to traverse the 00106 argument list more than once. 00107 00108 For ease of writing code which uses GCC extensions but needs to be 00109 portable to other compilers, we provide the GCC_VERSION macro that 00110 simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various 00111 wrappers around __attribute__. Also, __extension__ will be #defined 00112 to nothing if it doesn't work. See below. 00113 00114 This header also defines a lot of obsolete macros: 00115 CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID, 00116 AND, DOTS, NOARGS. Don't use them. */ 00117 00118 #ifndef _ANSIDECL_H 00119 #define _ANSIDECL_H 1 00120 00121 /* Every source file includes this file, 00122 so they will all get the switch for lint. */ 00123 /* LINTLIBRARY */ 00124 00125 /* Using MACRO(x,y) in cpp #if conditionals does not work with some 00126 older preprocessors. Thus we can't define something like this: 00127 00128 #define HAVE_GCC_VERSION(MAJOR, MINOR) \ 00129 (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR))) 00130 00131 and then test "#if HAVE_GCC_VERSION(2,7)". 00132 00133 So instead we use the macro below and test it against specific values. */ 00134 00135 /* This macro simplifies testing whether we are using gcc, and if it 00136 is of a particular minimum version. (Both major & minor numbers are 00137 significant.) This macro will evaluate to 0 if we are not using 00138 gcc at all. */ 00139 #ifndef GCC_VERSION 00140 #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) 00141 #endif /* GCC_VERSION */ 00142 00143 #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) || (defined(__alpha) && defined(__cplusplus)) 00144 /* All known AIX compilers implement these things (but don't always 00145 define __STDC__). The RISC/OS MIPS compiler defines these things 00146 in SVR4 mode, but does not define __STDC__. */ 00147 /* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other 00148 C++ compilers, does not define __STDC__, though it acts as if this 00149 was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */ 00150 00151 #define ANSI_PROTOTYPES 1 00152 #define PTR void * 00153 #define PTRCONST void *const 00154 #define LONG_DOUBLE long double 00155 00156 /* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in 00157 a #ifndef. */ 00158 #ifndef PARAMS 00159 #define PARAMS(ARGS) ARGS 00160 #endif 00161 00162 #define VPARAMS(ARGS) ARGS 00163 #define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR) 00164 00165 /* variadic function helper macros */ 00166 /* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's 00167 use without inhibiting further decls and without declaring an 00168 actual variable. */ 00169 #define VA_OPEN(AP, VAR) { va_list AP; va_start(AP, VAR); { struct Qdmy 00170 #define VA_CLOSE(AP) } va_end(AP); } 00171 #define VA_FIXEDARG(AP, T, N) struct Qdmy 00172 00173 #undef const 00174 #undef volatile 00175 #undef signed 00176 00177 /* inline requires special treatment; it's in C99, and GCC >=2.7 supports 00178 it too, but it's not in C89. */ 00179 #undef inline 00180 #if __STDC_VERSION__ > 199901L 00181 /* it's a keyword */ 00182 #else 00183 # if GCC_VERSION >= 2007 00184 # define inline __inline__ /* __inline__ prevents -pedantic warnings */ 00185 # else 00186 # define inline /* nothing */ 00187 # endif 00188 #endif 00189 00190 /* These are obsolete. Do not use. */ 00191 #ifndef IN_GCC 00192 #define CONST const 00193 #define VOLATILE volatile 00194 #define SIGNED signed 00195 00196 #define PROTO(type, name, arglist) type name arglist 00197 #define EXFUN(name, proto) name proto 00198 #define DEFUN(name, arglist, args) name(args) 00199 #define DEFUN_VOID(name) name(void) 00200 #define AND , 00201 #define DOTS , ... 00202 #define NOARGS void 00203 #endif /* ! IN_GCC */ 00204 00205 #else /* Not ANSI C. */ 00206 00207 #undef ANSI_PROTOTYPES 00208 #define PTR char * 00209 #define PTRCONST PTR 00210 #define LONG_DOUBLE double 00211 00212 #define PARAMS(args) () 00213 #define VPARAMS(args) (va_alist) va_dcl 00214 #define VA_START(va_list, var) va_start(va_list) 00215 00216 #define VA_OPEN(AP, VAR) { va_list AP; va_start(AP); { struct Qdmy 00217 #define VA_CLOSE(AP) } va_end(AP); } 00218 #define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE) 00219 00220 /* some systems define these in header files for non-ansi mode */ 00221 #undef const 00222 #undef volatile 00223 #undef signed 00224 #undef inline 00225 #define const 00226 #define volatile 00227 #define signed 00228 #define inline 00229 00230 #ifndef IN_GCC 00231 #define CONST 00232 #define VOLATILE 00233 #define SIGNED 00234 00235 #define PROTO(type, name, arglist) type name () 00236 #define EXFUN(name, proto) name() 00237 #define DEFUN(name, arglist, args) name arglist args; 00238 #define DEFUN_VOID(name) name() 00239 #define AND ; 00240 #define DOTS 00241 #define NOARGS 00242 #endif /* ! IN_GCC */ 00243 00244 #endif /* ANSI C. */ 00245 00246 /* Define macros for some gcc attributes. This permits us to use the 00247 macros freely, and know that they will come into play for the 00248 version of gcc in which they are supported. */ 00249 00250 #if (GCC_VERSION < 2007) 00251 # define __attribute__(x) 00252 #endif 00253 00254 /* Attribute __malloc__ on functions was valid as of gcc 2.96. */ 00255 #ifndef ATTRIBUTE_MALLOC 00256 # if (GCC_VERSION >= 2096) 00257 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) 00258 # else 00259 # define ATTRIBUTE_MALLOC 00260 # endif /* GNUC >= 2.96 */ 00261 #endif /* ATTRIBUTE_MALLOC */ 00262 00263 /* Attributes on labels were valid as of gcc 2.93. */ 00264 #ifndef ATTRIBUTE_UNUSED_LABEL 00265 # if (GCC_VERSION >= 2093) 00266 # define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED 00267 # else 00268 # define ATTRIBUTE_UNUSED_LABEL 00269 # endif /* GNUC >= 2.93 */ 00270 #endif /* ATTRIBUTE_UNUSED_LABEL */ 00271 00272 #ifndef ATTRIBUTE_UNUSED 00273 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 00274 #endif /* ATTRIBUTE_UNUSED */ 00275 00276 /* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the 00277 identifier name. */ 00278 #if ! defined(__cplusplus) || (GCC_VERSION >= 3004) 00279 # define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED 00280 #else /* !__cplusplus || GNUC >= 3.4 */ 00281 # define ARG_UNUSED(NAME) NAME 00282 #endif /* !__cplusplus || GNUC >= 3.4 */ 00283 00284 #ifndef ATTRIBUTE_NORETURN 00285 #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) 00286 #endif /* ATTRIBUTE_NORETURN */ 00287 00288 /* Attribute `nonnull' was valid as of gcc 3.3. */ 00289 #ifndef ATTRIBUTE_NONNULL 00290 # if (GCC_VERSION >= 3003) 00291 # define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m))) 00292 # else 00293 # define ATTRIBUTE_NONNULL(m) 00294 # endif /* GNUC >= 3.3 */ 00295 #endif /* ATTRIBUTE_NONNULL */ 00296 00297 /* Attribute `pure' was valid as of gcc 3.0. */ 00298 #ifndef ATTRIBUTE_PURE 00299 # if (GCC_VERSION >= 3000) 00300 # define ATTRIBUTE_PURE __attribute__ ((__pure__)) 00301 # else 00302 # define ATTRIBUTE_PURE 00303 # endif /* GNUC >= 3.0 */ 00304 #endif /* ATTRIBUTE_PURE */ 00305 00306 /* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL. 00307 This was the case for the `printf' format attribute by itself 00308 before GCC 3.3, but as of 3.3 we need to add the `nonnull' 00309 attribute to retain this behavior. */ 00310 #ifndef ATTRIBUTE_PRINTF 00311 #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m) 00312 #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2) 00313 #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3) 00314 #define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4) 00315 #define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5) 00316 #define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6) 00317 #endif /* ATTRIBUTE_PRINTF */ 00318 00319 /* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A 00320 NULL format specifier was allowed as of gcc 3.3. */ 00321 #ifndef ATTRIBUTE_NULL_PRINTF 00322 # if (GCC_VERSION >= 3003) 00323 # define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) 00324 # else 00325 # define ATTRIBUTE_NULL_PRINTF(m, n) 00326 # endif /* GNUC >= 3.3 */ 00327 # define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2) 00328 # define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3) 00329 # define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4) 00330 # define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5) 00331 # define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6) 00332 #endif /* ATTRIBUTE_NULL_PRINTF */ 00333 00334 /* Attribute `sentinel' was valid as of gcc 3.5. */ 00335 #ifndef ATTRIBUTE_SENTINEL 00336 # if (GCC_VERSION >= 3005) 00337 # define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__)) 00338 # else 00339 # define ATTRIBUTE_SENTINEL 00340 # endif /* GNUC >= 3.5 */ 00341 #endif /* ATTRIBUTE_SENTINEL */ 00342 00343 /* We use __extension__ in some places to suppress -pedantic warnings 00344 about GCC extensions. This feature didn't work properly before 00345 gcc 2.8. */ 00346 #if GCC_VERSION < 2008 00347 #define __extension__ 00348 #endif 00349 00350 #endif /* ansidecl.h */
1.5.6