1*404b540aSrobert /* ANSI and traditional C compatability macros 2*404b540aSrobert Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 3*404b540aSrobert Free Software Foundation, Inc. 4*404b540aSrobert This file is part of the GNU C Library. 5*404b540aSrobert 6*404b540aSrobert This program is free software; you can redistribute it and/or modify 7*404b540aSrobert it under the terms of the GNU General Public License as published by 8*404b540aSrobert the Free Software Foundation; either version 2 of the License, or 9*404b540aSrobert (at your option) any later version. 10*404b540aSrobert 11*404b540aSrobert This program is distributed in the hope that it will be useful, 12*404b540aSrobert but WITHOUT ANY WARRANTY; without even the implied warranty of 13*404b540aSrobert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*404b540aSrobert GNU General Public License for more details. 15*404b540aSrobert 16*404b540aSrobert You should have received a copy of the GNU General Public License 17*404b540aSrobert along with this program; if not, write to the Free Software 18*404b540aSrobert Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 19*404b540aSrobert 20*404b540aSrobert /* ANSI and traditional C compatibility macros 21*404b540aSrobert 22*404b540aSrobert ANSI C is assumed if __STDC__ is #defined. 23*404b540aSrobert 24*404b540aSrobert Macro ANSI C definition Traditional C definition 25*404b540aSrobert ----- ---- - ---------- ----------- - ---------- 26*404b540aSrobert ANSI_PROTOTYPES 1 not defined 27*404b540aSrobert PTR `void *' `char *' 28*404b540aSrobert PTRCONST `void *const' `char *' 29*404b540aSrobert LONG_DOUBLE `long double' `double' 30*404b540aSrobert const not defined `' 31*404b540aSrobert volatile not defined `' 32*404b540aSrobert signed not defined `' 33*404b540aSrobert VA_START(ap, var) va_start(ap, var) va_start(ap) 34*404b540aSrobert 35*404b540aSrobert Note that it is safe to write "void foo();" indicating a function 36*404b540aSrobert with no return value, in all K+R compilers we have been able to test. 37*404b540aSrobert 38*404b540aSrobert For declaring functions with prototypes, we also provide these: 39*404b540aSrobert 40*404b540aSrobert PARAMS ((prototype)) 41*404b540aSrobert -- for functions which take a fixed number of arguments. Use this 42*404b540aSrobert when declaring the function. When defining the function, write a 43*404b540aSrobert K+R style argument list. For example: 44*404b540aSrobert 45*404b540aSrobert char *strcpy PARAMS ((char *dest, char *source)); 46*404b540aSrobert ... 47*404b540aSrobert char * 48*404b540aSrobert strcpy (dest, source) 49*404b540aSrobert char *dest; 50*404b540aSrobert char *source; 51*404b540aSrobert { ... } 52*404b540aSrobert 53*404b540aSrobert 54*404b540aSrobert VPARAMS ((prototype, ...)) 55*404b540aSrobert -- for functions which take a variable number of arguments. Use 56*404b540aSrobert PARAMS to declare the function, VPARAMS to define it. For example: 57*404b540aSrobert 58*404b540aSrobert int printf PARAMS ((const char *format, ...)); 59*404b540aSrobert ... 60*404b540aSrobert int 61*404b540aSrobert printf VPARAMS ((const char *format, ...)) 62*404b540aSrobert { 63*404b540aSrobert ... 64*404b540aSrobert } 65*404b540aSrobert 66*404b540aSrobert For writing functions which take variable numbers of arguments, we 67*404b540aSrobert also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros. These 68*404b540aSrobert hide the differences between K+R <varargs.h> and C89 <stdarg.h> more 69*404b540aSrobert thoroughly than the simple VA_START() macro mentioned above. 70*404b540aSrobert 71*404b540aSrobert VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end. 72*404b540aSrobert Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls 73*404b540aSrobert corresponding to the list of fixed arguments. Then use va_arg 74*404b540aSrobert normally to get the variable arguments, or pass your va_list object 75*404b540aSrobert around. You do not declare the va_list yourself; VA_OPEN does it 76*404b540aSrobert for you. 77*404b540aSrobert 78*404b540aSrobert Here is a complete example: 79*404b540aSrobert 80*404b540aSrobert int 81*404b540aSrobert printf VPARAMS ((const char *format, ...)) 82*404b540aSrobert { 83*404b540aSrobert int result; 84*404b540aSrobert 85*404b540aSrobert VA_OPEN (ap, format); 86*404b540aSrobert VA_FIXEDARG (ap, const char *, format); 87*404b540aSrobert 88*404b540aSrobert result = vfprintf (stdout, format, ap); 89*404b540aSrobert VA_CLOSE (ap); 90*404b540aSrobert 91*404b540aSrobert return result; 92*404b540aSrobert } 93*404b540aSrobert 94*404b540aSrobert 95*404b540aSrobert You can declare variables either before or after the VA_OPEN, 96*404b540aSrobert VA_FIXEDARG sequence. Also, VA_OPEN and VA_CLOSE are the beginning 97*404b540aSrobert and end of a block. They must appear at the same nesting level, 98*404b540aSrobert and any variables declared after VA_OPEN go out of scope at 99*404b540aSrobert VA_CLOSE. Unfortunately, with a K+R compiler, that includes the 100*404b540aSrobert argument list. You can have multiple instances of VA_OPEN/VA_CLOSE 101*404b540aSrobert pairs in a single function in case you need to traverse the 102*404b540aSrobert argument list more than once. 103*404b540aSrobert 104*404b540aSrobert For ease of writing code which uses GCC extensions but needs to be 105*404b540aSrobert portable to other compilers, we provide the GCC_VERSION macro that 106*404b540aSrobert simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various 107*404b540aSrobert wrappers around __attribute__. Also, __extension__ will be #defined 108*404b540aSrobert to nothing if it doesn't work. See below. 109*404b540aSrobert 110*404b540aSrobert This header also defines a lot of obsolete macros: 111*404b540aSrobert CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID, 112*404b540aSrobert AND, DOTS, NOARGS. Don't use them. */ 113*404b540aSrobert 114*404b540aSrobert #ifndef _ANSIDECL_H 115*404b540aSrobert #define _ANSIDECL_H 1 116*404b540aSrobert 117*404b540aSrobert /* Every source file includes this file, 118*404b540aSrobert so they will all get the switch for lint. */ 119*404b540aSrobert /* LINTLIBRARY */ 120*404b540aSrobert 121*404b540aSrobert /* Using MACRO(x,y) in cpp #if conditionals does not work with some 122*404b540aSrobert older preprocessors. Thus we can't define something like this: 123*404b540aSrobert 124*404b540aSrobert #define HAVE_GCC_VERSION(MAJOR, MINOR) \ 125*404b540aSrobert (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR))) 126*404b540aSrobert 127*404b540aSrobert and then test "#if HAVE_GCC_VERSION(2,7)". 128*404b540aSrobert 129*404b540aSrobert So instead we use the macro below and test it against specific values. */ 130*404b540aSrobert 131*404b540aSrobert /* This macro simplifies testing whether we are using gcc, and if it 132*404b540aSrobert is of a particular minimum version. (Both major & minor numbers are 133*404b540aSrobert significant.) This macro will evaluate to 0 if we are not using 134*404b540aSrobert gcc at all. */ 135*404b540aSrobert #ifndef GCC_VERSION 136*404b540aSrobert #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) 137*404b540aSrobert #endif /* GCC_VERSION */ 138*404b540aSrobert 139*404b540aSrobert #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) || (defined(__alpha) && defined(__cplusplus)) 140*404b540aSrobert /* All known AIX compilers implement these things (but don't always 141*404b540aSrobert define __STDC__). The RISC/OS MIPS compiler defines these things 142*404b540aSrobert in SVR4 mode, but does not define __STDC__. */ 143*404b540aSrobert /* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other 144*404b540aSrobert C++ compilers, does not define __STDC__, though it acts as if this 145*404b540aSrobert was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */ 146*404b540aSrobert 147*404b540aSrobert #define ANSI_PROTOTYPES 1 148*404b540aSrobert #define PTR void * 149*404b540aSrobert #define PTRCONST void *const 150*404b540aSrobert #define LONG_DOUBLE long double 151*404b540aSrobert 152*404b540aSrobert /* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in 153*404b540aSrobert a #ifndef. */ 154*404b540aSrobert #ifndef PARAMS 155*404b540aSrobert #define PARAMS(ARGS) ARGS 156*404b540aSrobert #endif 157*404b540aSrobert 158*404b540aSrobert #define VPARAMS(ARGS) ARGS 159*404b540aSrobert #define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR) 160*404b540aSrobert 161*404b540aSrobert /* variadic function helper macros */ 162*404b540aSrobert /* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's 163*404b540aSrobert use without inhibiting further decls and without declaring an 164*404b540aSrobert actual variable. */ 165*404b540aSrobert #define VA_OPEN(AP, VAR) { va_list AP; va_start(AP, VAR); { struct Qdmy 166*404b540aSrobert #define VA_CLOSE(AP) } va_end(AP); } 167*404b540aSrobert #define VA_FIXEDARG(AP, T, N) struct Qdmy 168*404b540aSrobert 169*404b540aSrobert #undef const 170*404b540aSrobert #undef volatile 171*404b540aSrobert #undef signed 172*404b540aSrobert 173*404b540aSrobert /* inline requires special treatment; it's in C99, and GCC >=2.7 supports 174*404b540aSrobert it too, but it's not in C89. */ 175*404b540aSrobert #undef inline 176*404b540aSrobert #if __STDC_VERSION__ > 199901L 177*404b540aSrobert /* it's a keyword */ 178*404b540aSrobert #else 179*404b540aSrobert # if GCC_VERSION >= 2007 180*404b540aSrobert # define inline __inline__ /* __inline__ prevents -pedantic warnings */ 181*404b540aSrobert # else 182*404b540aSrobert # define inline /* nothing */ 183*404b540aSrobert # endif 184*404b540aSrobert #endif 185*404b540aSrobert 186*404b540aSrobert /* These are obsolete. Do not use. */ 187*404b540aSrobert #ifndef IN_GCC 188*404b540aSrobert #define CONST const 189*404b540aSrobert #define VOLATILE volatile 190*404b540aSrobert #define SIGNED signed 191*404b540aSrobert 192*404b540aSrobert #define PROTO(type, name, arglist) type name arglist 193*404b540aSrobert #define EXFUN(name, proto) name proto 194*404b540aSrobert #define DEFUN(name, arglist, args) name(args) 195*404b540aSrobert #define DEFUN_VOID(name) name(void) 196*404b540aSrobert #define AND , 197*404b540aSrobert #define DOTS , ... 198*404b540aSrobert #define NOARGS void 199*404b540aSrobert #endif /* ! IN_GCC */ 200*404b540aSrobert 201*404b540aSrobert #else /* Not ANSI C. */ 202*404b540aSrobert 203*404b540aSrobert #undef ANSI_PROTOTYPES 204*404b540aSrobert #define PTR char * 205*404b540aSrobert #define PTRCONST PTR 206*404b540aSrobert #define LONG_DOUBLE double 207*404b540aSrobert 208*404b540aSrobert #define PARAMS(args) () 209*404b540aSrobert #define VPARAMS(args) (va_alist) va_dcl 210*404b540aSrobert #define VA_START(va_list, var) va_start(va_list) 211*404b540aSrobert 212*404b540aSrobert #define VA_OPEN(AP, VAR) { va_list AP; va_start(AP); { struct Qdmy 213*404b540aSrobert #define VA_CLOSE(AP) } va_end(AP); } 214*404b540aSrobert #define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE) 215*404b540aSrobert 216*404b540aSrobert /* some systems define these in header files for non-ansi mode */ 217*404b540aSrobert #undef const 218*404b540aSrobert #undef volatile 219*404b540aSrobert #undef signed 220*404b540aSrobert #undef inline 221*404b540aSrobert #define const 222*404b540aSrobert #define volatile 223*404b540aSrobert #define signed 224*404b540aSrobert #define inline 225*404b540aSrobert 226*404b540aSrobert #ifndef IN_GCC 227*404b540aSrobert #define CONST 228*404b540aSrobert #define VOLATILE 229*404b540aSrobert #define SIGNED 230*404b540aSrobert 231*404b540aSrobert #define PROTO(type, name, arglist) type name () 232*404b540aSrobert #define EXFUN(name, proto) name() 233*404b540aSrobert #define DEFUN(name, arglist, args) name arglist args; 234*404b540aSrobert #define DEFUN_VOID(name) name() 235*404b540aSrobert #define AND ; 236*404b540aSrobert #define DOTS 237*404b540aSrobert #define NOARGS 238*404b540aSrobert #endif /* ! IN_GCC */ 239*404b540aSrobert 240*404b540aSrobert #endif /* ANSI C. */ 241*404b540aSrobert 242*404b540aSrobert /* Define macros for some gcc attributes. This permits us to use the 243*404b540aSrobert macros freely, and know that they will come into play for the 244*404b540aSrobert version of gcc in which they are supported. */ 245*404b540aSrobert 246*404b540aSrobert #if (GCC_VERSION < 2007) 247*404b540aSrobert # define __attribute__(x) 248*404b540aSrobert #endif 249*404b540aSrobert 250*404b540aSrobert /* Attribute __malloc__ on functions was valid as of gcc 2.96. */ 251*404b540aSrobert #ifndef ATTRIBUTE_MALLOC 252*404b540aSrobert # if (GCC_VERSION >= 2096) 253*404b540aSrobert # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) 254*404b540aSrobert # else 255*404b540aSrobert # define ATTRIBUTE_MALLOC 256*404b540aSrobert # endif /* GNUC >= 2.96 */ 257*404b540aSrobert #endif /* ATTRIBUTE_MALLOC */ 258*404b540aSrobert 259*404b540aSrobert /* Attributes on labels were valid as of gcc 2.93. */ 260*404b540aSrobert #ifndef ATTRIBUTE_UNUSED_LABEL 261*404b540aSrobert # if (!defined (__cplusplus) && GCC_VERSION >= 2093) 262*404b540aSrobert # define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED 263*404b540aSrobert # else 264*404b540aSrobert # define ATTRIBUTE_UNUSED_LABEL 265*404b540aSrobert # endif /* !__cplusplus && GNUC >= 2.93 */ 266*404b540aSrobert #endif /* ATTRIBUTE_UNUSED_LABEL */ 267*404b540aSrobert 268*404b540aSrobert #ifndef ATTRIBUTE_UNUSED 269*404b540aSrobert #define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 270*404b540aSrobert #endif /* ATTRIBUTE_UNUSED */ 271*404b540aSrobert 272*404b540aSrobert /* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the 273*404b540aSrobert identifier name. */ 274*404b540aSrobert #if ! defined(__cplusplus) || (GCC_VERSION >= 3004) 275*404b540aSrobert # define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED 276*404b540aSrobert #else /* !__cplusplus || GNUC >= 3.4 */ 277*404b540aSrobert # define ARG_UNUSED(NAME) NAME 278*404b540aSrobert #endif /* !__cplusplus || GNUC >= 3.4 */ 279*404b540aSrobert 280*404b540aSrobert #ifndef ATTRIBUTE_NORETURN 281*404b540aSrobert #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) 282*404b540aSrobert #endif /* ATTRIBUTE_NORETURN */ 283*404b540aSrobert 284*404b540aSrobert /* Attribute `nonnull' was valid as of gcc 3.3. */ 285*404b540aSrobert #ifndef ATTRIBUTE_NONNULL 286*404b540aSrobert # if (GCC_VERSION >= 3003) 287*404b540aSrobert # define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m))) 288*404b540aSrobert # else 289*404b540aSrobert # define ATTRIBUTE_NONNULL(m) 290*404b540aSrobert # endif /* GNUC >= 3.3 */ 291*404b540aSrobert #endif /* ATTRIBUTE_NONNULL */ 292*404b540aSrobert 293*404b540aSrobert /* Attribute `pure' was valid as of gcc 3.0. */ 294*404b540aSrobert #ifndef ATTRIBUTE_PURE 295*404b540aSrobert # if (GCC_VERSION >= 3000) 296*404b540aSrobert # define ATTRIBUTE_PURE __attribute__ ((__pure__)) 297*404b540aSrobert # else 298*404b540aSrobert # define ATTRIBUTE_PURE 299*404b540aSrobert # endif /* GNUC >= 3.0 */ 300*404b540aSrobert #endif /* ATTRIBUTE_PURE */ 301*404b540aSrobert 302*404b540aSrobert /* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL. 303*404b540aSrobert This was the case for the `printf' format attribute by itself 304*404b540aSrobert before GCC 3.3, but as of 3.3 we need to add the `nonnull' 305*404b540aSrobert attribute to retain this behavior. */ 306*404b540aSrobert #ifndef ATTRIBUTE_PRINTF 307*404b540aSrobert #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m) 308*404b540aSrobert #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2) 309*404b540aSrobert #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3) 310*404b540aSrobert #define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4) 311*404b540aSrobert #define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5) 312*404b540aSrobert #define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6) 313*404b540aSrobert #endif /* ATTRIBUTE_PRINTF */ 314*404b540aSrobert 315*404b540aSrobert /* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on 316*404b540aSrobert a function pointer. Format attributes were allowed on function 317*404b540aSrobert pointers as of gcc 3.1. */ 318*404b540aSrobert #ifndef ATTRIBUTE_FPTR_PRINTF 319*404b540aSrobert # if (GCC_VERSION >= 3001) 320*404b540aSrobert # define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n) 321*404b540aSrobert # else 322*404b540aSrobert # define ATTRIBUTE_FPTR_PRINTF(m, n) 323*404b540aSrobert # endif /* GNUC >= 3.1 */ 324*404b540aSrobert # define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2) 325*404b540aSrobert # define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3) 326*404b540aSrobert # define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4) 327*404b540aSrobert # define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5) 328*404b540aSrobert # define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6) 329*404b540aSrobert #endif /* ATTRIBUTE_FPTR_PRINTF */ 330*404b540aSrobert 331*404b540aSrobert /* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A 332*404b540aSrobert NULL format specifier was allowed as of gcc 3.3. */ 333*404b540aSrobert #ifndef ATTRIBUTE_NULL_PRINTF 334*404b540aSrobert # if (GCC_VERSION >= 3003) 335*404b540aSrobert # define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) 336*404b540aSrobert # else 337*404b540aSrobert # define ATTRIBUTE_NULL_PRINTF(m, n) 338*404b540aSrobert # endif /* GNUC >= 3.3 */ 339*404b540aSrobert # define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2) 340*404b540aSrobert # define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3) 341*404b540aSrobert # define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4) 342*404b540aSrobert # define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5) 343*404b540aSrobert # define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6) 344*404b540aSrobert #endif /* ATTRIBUTE_NULL_PRINTF */ 345*404b540aSrobert 346*404b540aSrobert /* Attribute `sentinel' was valid as of gcc 3.5. */ 347*404b540aSrobert #ifndef ATTRIBUTE_SENTINEL 348*404b540aSrobert # if (GCC_VERSION >= 3005) 349*404b540aSrobert # define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__)) 350*404b540aSrobert # else 351*404b540aSrobert # define ATTRIBUTE_SENTINEL 352*404b540aSrobert # endif /* GNUC >= 3.5 */ 353*404b540aSrobert #endif /* ATTRIBUTE_SENTINEL */ 354*404b540aSrobert 355*404b540aSrobert 356*404b540aSrobert #ifndef ATTRIBUTE_ALIGNED_ALIGNOF 357*404b540aSrobert # if (GCC_VERSION >= 3000) 358*404b540aSrobert # define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m)))) 359*404b540aSrobert # else 360*404b540aSrobert # define ATTRIBUTE_ALIGNED_ALIGNOF(m) 361*404b540aSrobert # endif /* GNUC >= 3.0 */ 362*404b540aSrobert #endif /* ATTRIBUTE_ALIGNED_ALIGNOF */ 363*404b540aSrobert 364*404b540aSrobert /* We use __extension__ in some places to suppress -pedantic warnings 365*404b540aSrobert about GCC extensions. This feature didn't work properly before 366*404b540aSrobert gcc 2.8. */ 367*404b540aSrobert #if GCC_VERSION < 2008 368*404b540aSrobert #define __extension__ 369*404b540aSrobert #endif 370*404b540aSrobert 371*404b540aSrobert #endif /* ansidecl.h */ 372