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