15796c8dcSSimon Schubert /* ANSI and traditional C compatability macros 25796c8dcSSimon Schubert Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 3cf7f2e2dSJohn Marino 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 45796c8dcSSimon Schubert Free Software Foundation, Inc. 55796c8dcSSimon Schubert This file is part of the GNU C Library. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 95796c8dcSSimon Schubert the Free Software Foundation; either version 2 of the License, or 105796c8dcSSimon Schubert (at your option) any later version. 115796c8dcSSimon Schubert 125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 155796c8dcSSimon Schubert GNU General Public License for more details. 165796c8dcSSimon Schubert 175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 185796c8dcSSimon Schubert along with this program; if not, write to the Free Software 195796c8dcSSimon Schubert Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 205796c8dcSSimon Schubert 215796c8dcSSimon Schubert /* ANSI and traditional C compatibility macros 225796c8dcSSimon Schubert 235796c8dcSSimon Schubert ANSI C is assumed if __STDC__ is #defined. 245796c8dcSSimon Schubert 255796c8dcSSimon Schubert Macro ANSI C definition Traditional C definition 265796c8dcSSimon Schubert ----- ---- - ---------- ----------- - ---------- 275796c8dcSSimon Schubert ANSI_PROTOTYPES 1 not defined 285796c8dcSSimon Schubert PTR `void *' `char *' 295796c8dcSSimon Schubert PTRCONST `void *const' `char *' 305796c8dcSSimon Schubert LONG_DOUBLE `long double' `double' 315796c8dcSSimon Schubert const not defined `' 325796c8dcSSimon Schubert volatile not defined `' 335796c8dcSSimon Schubert signed not defined `' 345796c8dcSSimon Schubert VA_START(ap, var) va_start(ap, var) va_start(ap) 355796c8dcSSimon Schubert 365796c8dcSSimon Schubert Note that it is safe to write "void foo();" indicating a function 375796c8dcSSimon Schubert with no return value, in all K+R compilers we have been able to test. 385796c8dcSSimon Schubert 395796c8dcSSimon Schubert For declaring functions with prototypes, we also provide these: 405796c8dcSSimon Schubert 415796c8dcSSimon Schubert PARAMS ((prototype)) 425796c8dcSSimon Schubert -- for functions which take a fixed number of arguments. Use this 435796c8dcSSimon Schubert when declaring the function. When defining the function, write a 445796c8dcSSimon Schubert K+R style argument list. For example: 455796c8dcSSimon Schubert 465796c8dcSSimon Schubert char *strcpy PARAMS ((char *dest, char *source)); 475796c8dcSSimon Schubert ... 485796c8dcSSimon Schubert char * 495796c8dcSSimon Schubert strcpy (dest, source) 505796c8dcSSimon Schubert char *dest; 515796c8dcSSimon Schubert char *source; 525796c8dcSSimon Schubert { ... } 535796c8dcSSimon Schubert 545796c8dcSSimon Schubert 555796c8dcSSimon Schubert VPARAMS ((prototype, ...)) 565796c8dcSSimon Schubert -- for functions which take a variable number of arguments. Use 575796c8dcSSimon Schubert PARAMS to declare the function, VPARAMS to define it. For example: 585796c8dcSSimon Schubert 595796c8dcSSimon Schubert int printf PARAMS ((const char *format, ...)); 605796c8dcSSimon Schubert ... 615796c8dcSSimon Schubert int 625796c8dcSSimon Schubert printf VPARAMS ((const char *format, ...)) 635796c8dcSSimon Schubert { 645796c8dcSSimon Schubert ... 655796c8dcSSimon Schubert } 665796c8dcSSimon Schubert 675796c8dcSSimon Schubert For writing functions which take variable numbers of arguments, we 685796c8dcSSimon Schubert also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros. These 695796c8dcSSimon Schubert hide the differences between K+R <varargs.h> and C89 <stdarg.h> more 705796c8dcSSimon Schubert thoroughly than the simple VA_START() macro mentioned above. 715796c8dcSSimon Schubert 725796c8dcSSimon Schubert VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end. 735796c8dcSSimon Schubert Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls 745796c8dcSSimon Schubert corresponding to the list of fixed arguments. Then use va_arg 755796c8dcSSimon Schubert normally to get the variable arguments, or pass your va_list object 765796c8dcSSimon Schubert around. You do not declare the va_list yourself; VA_OPEN does it 775796c8dcSSimon Schubert for you. 785796c8dcSSimon Schubert 795796c8dcSSimon Schubert Here is a complete example: 805796c8dcSSimon Schubert 815796c8dcSSimon Schubert int 825796c8dcSSimon Schubert printf VPARAMS ((const char *format, ...)) 835796c8dcSSimon Schubert { 845796c8dcSSimon Schubert int result; 855796c8dcSSimon Schubert 865796c8dcSSimon Schubert VA_OPEN (ap, format); 875796c8dcSSimon Schubert VA_FIXEDARG (ap, const char *, format); 885796c8dcSSimon Schubert 895796c8dcSSimon Schubert result = vfprintf (stdout, format, ap); 905796c8dcSSimon Schubert VA_CLOSE (ap); 915796c8dcSSimon Schubert 925796c8dcSSimon Schubert return result; 935796c8dcSSimon Schubert } 945796c8dcSSimon Schubert 955796c8dcSSimon Schubert 965796c8dcSSimon Schubert You can declare variables either before or after the VA_OPEN, 975796c8dcSSimon Schubert VA_FIXEDARG sequence. Also, VA_OPEN and VA_CLOSE are the beginning 985796c8dcSSimon Schubert and end of a block. They must appear at the same nesting level, 995796c8dcSSimon Schubert and any variables declared after VA_OPEN go out of scope at 1005796c8dcSSimon Schubert VA_CLOSE. Unfortunately, with a K+R compiler, that includes the 1015796c8dcSSimon Schubert argument list. You can have multiple instances of VA_OPEN/VA_CLOSE 1025796c8dcSSimon Schubert pairs in a single function in case you need to traverse the 1035796c8dcSSimon Schubert argument list more than once. 1045796c8dcSSimon Schubert 1055796c8dcSSimon Schubert For ease of writing code which uses GCC extensions but needs to be 1065796c8dcSSimon Schubert portable to other compilers, we provide the GCC_VERSION macro that 1075796c8dcSSimon Schubert simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various 1085796c8dcSSimon Schubert wrappers around __attribute__. Also, __extension__ will be #defined 1095796c8dcSSimon Schubert to nothing if it doesn't work. See below. 1105796c8dcSSimon Schubert 1115796c8dcSSimon Schubert This header also defines a lot of obsolete macros: 1125796c8dcSSimon Schubert CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID, 1135796c8dcSSimon Schubert AND, DOTS, NOARGS. Don't use them. */ 1145796c8dcSSimon Schubert 1155796c8dcSSimon Schubert #ifndef _ANSIDECL_H 1165796c8dcSSimon Schubert #define _ANSIDECL_H 1 1175796c8dcSSimon Schubert 1185796c8dcSSimon Schubert #ifdef __cplusplus 1195796c8dcSSimon Schubert extern "C" { 1205796c8dcSSimon Schubert #endif 1215796c8dcSSimon Schubert 1225796c8dcSSimon Schubert /* Every source file includes this file, 1235796c8dcSSimon Schubert so they will all get the switch for lint. */ 1245796c8dcSSimon Schubert /* LINTLIBRARY */ 1255796c8dcSSimon Schubert 1265796c8dcSSimon Schubert /* Using MACRO(x,y) in cpp #if conditionals does not work with some 1275796c8dcSSimon Schubert older preprocessors. Thus we can't define something like this: 1285796c8dcSSimon Schubert 1295796c8dcSSimon Schubert #define HAVE_GCC_VERSION(MAJOR, MINOR) \ 1305796c8dcSSimon Schubert (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR))) 1315796c8dcSSimon Schubert 1325796c8dcSSimon Schubert and then test "#if HAVE_GCC_VERSION(2,7)". 1335796c8dcSSimon Schubert 1345796c8dcSSimon Schubert So instead we use the macro below and test it against specific values. */ 1355796c8dcSSimon Schubert 1365796c8dcSSimon Schubert /* This macro simplifies testing whether we are using gcc, and if it 1375796c8dcSSimon Schubert is of a particular minimum version. (Both major & minor numbers are 1385796c8dcSSimon Schubert significant.) This macro will evaluate to 0 if we are not using 1395796c8dcSSimon Schubert gcc at all. */ 1405796c8dcSSimon Schubert #ifndef GCC_VERSION 1415796c8dcSSimon Schubert #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) 1425796c8dcSSimon Schubert #endif /* GCC_VERSION */ 1435796c8dcSSimon Schubert 1445796c8dcSSimon Schubert #if defined (__STDC__) || defined(__cplusplus) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) 1455796c8dcSSimon Schubert /* All known AIX compilers implement these things (but don't always 1465796c8dcSSimon Schubert define __STDC__). The RISC/OS MIPS compiler defines these things 1475796c8dcSSimon Schubert in SVR4 mode, but does not define __STDC__. */ 1485796c8dcSSimon Schubert /* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other 1495796c8dcSSimon Schubert C++ compilers, does not define __STDC__, though it acts as if this 1505796c8dcSSimon Schubert was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */ 1515796c8dcSSimon Schubert 1525796c8dcSSimon Schubert #define ANSI_PROTOTYPES 1 1535796c8dcSSimon Schubert #define PTR void * 1545796c8dcSSimon Schubert #define PTRCONST void *const 1555796c8dcSSimon Schubert #define LONG_DOUBLE long double 1565796c8dcSSimon Schubert 1575796c8dcSSimon Schubert /* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in 1585796c8dcSSimon Schubert a #ifndef. */ 1595796c8dcSSimon Schubert #ifndef PARAMS 1605796c8dcSSimon Schubert #define PARAMS(ARGS) ARGS 1615796c8dcSSimon Schubert #endif 1625796c8dcSSimon Schubert 1635796c8dcSSimon Schubert #define VPARAMS(ARGS) ARGS 1645796c8dcSSimon Schubert #define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR) 1655796c8dcSSimon Schubert 1665796c8dcSSimon Schubert /* variadic function helper macros */ 1675796c8dcSSimon Schubert /* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's 1685796c8dcSSimon Schubert use without inhibiting further decls and without declaring an 1695796c8dcSSimon Schubert actual variable. */ 1705796c8dcSSimon Schubert #define VA_OPEN(AP, VAR) { va_list AP; va_start(AP, VAR); { struct Qdmy 1715796c8dcSSimon Schubert #define VA_CLOSE(AP) } va_end(AP); } 1725796c8dcSSimon Schubert #define VA_FIXEDARG(AP, T, N) struct Qdmy 1735796c8dcSSimon Schubert 1745796c8dcSSimon Schubert #undef const 1755796c8dcSSimon Schubert #undef volatile 1765796c8dcSSimon Schubert #undef signed 1775796c8dcSSimon Schubert 1785796c8dcSSimon Schubert /* inline requires special treatment; it's in C99, and GCC >=2.7 supports 1795796c8dcSSimon Schubert it too, but it's not in C89. */ 1805796c8dcSSimon Schubert #undef inline 181cf7f2e2dSJohn Marino #if __STDC_VERSION__ >= 199901L || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__)) 1825796c8dcSSimon Schubert /* it's a keyword */ 1835796c8dcSSimon Schubert #else 1845796c8dcSSimon Schubert # if GCC_VERSION >= 2007 1855796c8dcSSimon Schubert # define inline __inline__ /* __inline__ prevents -pedantic warnings */ 1865796c8dcSSimon Schubert # else 1875796c8dcSSimon Schubert # define inline /* nothing */ 1885796c8dcSSimon Schubert # endif 1895796c8dcSSimon Schubert #endif 1905796c8dcSSimon Schubert 1915796c8dcSSimon Schubert /* These are obsolete. Do not use. */ 1925796c8dcSSimon Schubert #ifndef IN_GCC 1935796c8dcSSimon Schubert #define CONST const 1945796c8dcSSimon Schubert #define VOLATILE volatile 1955796c8dcSSimon Schubert #define SIGNED signed 1965796c8dcSSimon Schubert 1975796c8dcSSimon Schubert #define PROTO(type, name, arglist) type name arglist 1985796c8dcSSimon Schubert #define EXFUN(name, proto) name proto 1995796c8dcSSimon Schubert #define DEFUN(name, arglist, args) name(args) 2005796c8dcSSimon Schubert #define DEFUN_VOID(name) name(void) 2015796c8dcSSimon Schubert #define AND , 2025796c8dcSSimon Schubert #define DOTS , ... 2035796c8dcSSimon Schubert #define NOARGS void 2045796c8dcSSimon Schubert #endif /* ! IN_GCC */ 2055796c8dcSSimon Schubert 2065796c8dcSSimon Schubert #else /* Not ANSI C. */ 2075796c8dcSSimon Schubert 2085796c8dcSSimon Schubert #undef ANSI_PROTOTYPES 2095796c8dcSSimon Schubert #define PTR char * 2105796c8dcSSimon Schubert #define PTRCONST PTR 2115796c8dcSSimon Schubert #define LONG_DOUBLE double 2125796c8dcSSimon Schubert 2135796c8dcSSimon Schubert #define PARAMS(args) () 2145796c8dcSSimon Schubert #define VPARAMS(args) (va_alist) va_dcl 2155796c8dcSSimon Schubert #define VA_START(va_list, var) va_start(va_list) 2165796c8dcSSimon Schubert 2175796c8dcSSimon Schubert #define VA_OPEN(AP, VAR) { va_list AP; va_start(AP); { struct Qdmy 2185796c8dcSSimon Schubert #define VA_CLOSE(AP) } va_end(AP); } 2195796c8dcSSimon Schubert #define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE) 2205796c8dcSSimon Schubert 2215796c8dcSSimon Schubert /* some systems define these in header files for non-ansi mode */ 2225796c8dcSSimon Schubert #undef const 2235796c8dcSSimon Schubert #undef volatile 2245796c8dcSSimon Schubert #undef signed 2255796c8dcSSimon Schubert #undef inline 2265796c8dcSSimon Schubert #define const 2275796c8dcSSimon Schubert #define volatile 2285796c8dcSSimon Schubert #define signed 2295796c8dcSSimon Schubert #define inline 2305796c8dcSSimon Schubert 2315796c8dcSSimon Schubert #ifndef IN_GCC 2325796c8dcSSimon Schubert #define CONST 2335796c8dcSSimon Schubert #define VOLATILE 2345796c8dcSSimon Schubert #define SIGNED 2355796c8dcSSimon Schubert 2365796c8dcSSimon Schubert #define PROTO(type, name, arglist) type name () 2375796c8dcSSimon Schubert #define EXFUN(name, proto) name() 2385796c8dcSSimon Schubert #define DEFUN(name, arglist, args) name arglist args; 2395796c8dcSSimon Schubert #define DEFUN_VOID(name) name() 2405796c8dcSSimon Schubert #define AND ; 2415796c8dcSSimon Schubert #define DOTS 2425796c8dcSSimon Schubert #define NOARGS 2435796c8dcSSimon Schubert #endif /* ! IN_GCC */ 2445796c8dcSSimon Schubert 2455796c8dcSSimon Schubert #endif /* ANSI C. */ 2465796c8dcSSimon Schubert 2475796c8dcSSimon Schubert /* Define macros for some gcc attributes. This permits us to use the 2485796c8dcSSimon Schubert macros freely, and know that they will come into play for the 2495796c8dcSSimon Schubert version of gcc in which they are supported. */ 2505796c8dcSSimon Schubert 2515796c8dcSSimon Schubert #if (GCC_VERSION < 2007) 2525796c8dcSSimon Schubert # define __attribute__(x) 2535796c8dcSSimon Schubert #endif 2545796c8dcSSimon Schubert 2555796c8dcSSimon Schubert /* Attribute __malloc__ on functions was valid as of gcc 2.96. */ 2565796c8dcSSimon Schubert #ifndef ATTRIBUTE_MALLOC 2575796c8dcSSimon Schubert # if (GCC_VERSION >= 2096) 2585796c8dcSSimon Schubert # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) 2595796c8dcSSimon Schubert # else 2605796c8dcSSimon Schubert # define ATTRIBUTE_MALLOC 2615796c8dcSSimon Schubert # endif /* GNUC >= 2.96 */ 2625796c8dcSSimon Schubert #endif /* ATTRIBUTE_MALLOC */ 2635796c8dcSSimon Schubert 2645796c8dcSSimon Schubert /* Attributes on labels were valid as of gcc 2.93 and g++ 4.5. For 2655796c8dcSSimon Schubert g++ an attribute on a label must be followed by a semicolon. */ 2665796c8dcSSimon Schubert #ifndef ATTRIBUTE_UNUSED_LABEL 2675796c8dcSSimon Schubert # ifndef __cplusplus 2685796c8dcSSimon Schubert # if GCC_VERSION >= 2093 2695796c8dcSSimon Schubert # define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED 2705796c8dcSSimon Schubert # else 2715796c8dcSSimon Schubert # define ATTRIBUTE_UNUSED_LABEL 2725796c8dcSSimon Schubert # endif 2735796c8dcSSimon Schubert # else 2745796c8dcSSimon Schubert # if GCC_VERSION >= 4005 2755796c8dcSSimon Schubert # define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED ; 2765796c8dcSSimon Schubert # else 2775796c8dcSSimon Schubert # define ATTRIBUTE_UNUSED_LABEL 2785796c8dcSSimon Schubert # endif 2795796c8dcSSimon Schubert # endif 2805796c8dcSSimon Schubert #endif 2815796c8dcSSimon Schubert 282*ef5ccd6cSJohn Marino /* Similarly to ARG_UNUSED below. Prior to GCC 3.4, the C++ frontend 283*ef5ccd6cSJohn Marino couldn't parse attributes placed after the identifier name, and now 284*ef5ccd6cSJohn Marino the entire compiler is built with C++. */ 2855796c8dcSSimon Schubert #ifndef ATTRIBUTE_UNUSED 286*ef5ccd6cSJohn Marino #if GCC_VERSION >= 3004 2875796c8dcSSimon Schubert # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 288*ef5ccd6cSJohn Marino #else 289*ef5ccd6cSJohn Marino #define ATTRIBUTE_UNUSED 290*ef5ccd6cSJohn Marino #endif 2915796c8dcSSimon Schubert #endif /* ATTRIBUTE_UNUSED */ 2925796c8dcSSimon Schubert 2935796c8dcSSimon Schubert /* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the 2945796c8dcSSimon Schubert identifier name. */ 2955796c8dcSSimon Schubert #if ! defined(__cplusplus) || (GCC_VERSION >= 3004) 2965796c8dcSSimon Schubert # define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED 2975796c8dcSSimon Schubert #else /* !__cplusplus || GNUC >= 3.4 */ 2985796c8dcSSimon Schubert # define ARG_UNUSED(NAME) NAME 2995796c8dcSSimon Schubert #endif /* !__cplusplus || GNUC >= 3.4 */ 3005796c8dcSSimon Schubert 3015796c8dcSSimon Schubert #ifndef ATTRIBUTE_NORETURN 3025796c8dcSSimon Schubert #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) 3035796c8dcSSimon Schubert #endif /* ATTRIBUTE_NORETURN */ 3045796c8dcSSimon Schubert 3055796c8dcSSimon Schubert /* Attribute `nonnull' was valid as of gcc 3.3. */ 3065796c8dcSSimon Schubert #ifndef ATTRIBUTE_NONNULL 3075796c8dcSSimon Schubert # if (GCC_VERSION >= 3003) 3085796c8dcSSimon Schubert # define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m))) 3095796c8dcSSimon Schubert # else 3105796c8dcSSimon Schubert # define ATTRIBUTE_NONNULL(m) 3115796c8dcSSimon Schubert # endif /* GNUC >= 3.3 */ 3125796c8dcSSimon Schubert #endif /* ATTRIBUTE_NONNULL */ 3135796c8dcSSimon Schubert 3145796c8dcSSimon Schubert /* Attribute `pure' was valid as of gcc 3.0. */ 3155796c8dcSSimon Schubert #ifndef ATTRIBUTE_PURE 3165796c8dcSSimon Schubert # if (GCC_VERSION >= 3000) 3175796c8dcSSimon Schubert # define ATTRIBUTE_PURE __attribute__ ((__pure__)) 3185796c8dcSSimon Schubert # else 3195796c8dcSSimon Schubert # define ATTRIBUTE_PURE 3205796c8dcSSimon Schubert # endif /* GNUC >= 3.0 */ 3215796c8dcSSimon Schubert #endif /* ATTRIBUTE_PURE */ 3225796c8dcSSimon Schubert 3235796c8dcSSimon Schubert /* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL. 3245796c8dcSSimon Schubert This was the case for the `printf' format attribute by itself 3255796c8dcSSimon Schubert before GCC 3.3, but as of 3.3 we need to add the `nonnull' 3265796c8dcSSimon Schubert attribute to retain this behavior. */ 3275796c8dcSSimon Schubert #ifndef ATTRIBUTE_PRINTF 3285796c8dcSSimon Schubert #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m) 3295796c8dcSSimon Schubert #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2) 3305796c8dcSSimon Schubert #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3) 3315796c8dcSSimon Schubert #define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4) 3325796c8dcSSimon Schubert #define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5) 3335796c8dcSSimon Schubert #define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6) 3345796c8dcSSimon Schubert #endif /* ATTRIBUTE_PRINTF */ 3355796c8dcSSimon Schubert 3365796c8dcSSimon Schubert /* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on 3375796c8dcSSimon Schubert a function pointer. Format attributes were allowed on function 3385796c8dcSSimon Schubert pointers as of gcc 3.1. */ 3395796c8dcSSimon Schubert #ifndef ATTRIBUTE_FPTR_PRINTF 3405796c8dcSSimon Schubert # if (GCC_VERSION >= 3001) 3415796c8dcSSimon Schubert # define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n) 3425796c8dcSSimon Schubert # else 3435796c8dcSSimon Schubert # define ATTRIBUTE_FPTR_PRINTF(m, n) 3445796c8dcSSimon Schubert # endif /* GNUC >= 3.1 */ 3455796c8dcSSimon Schubert # define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2) 3465796c8dcSSimon Schubert # define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3) 3475796c8dcSSimon Schubert # define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4) 3485796c8dcSSimon Schubert # define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5) 3495796c8dcSSimon Schubert # define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6) 3505796c8dcSSimon Schubert #endif /* ATTRIBUTE_FPTR_PRINTF */ 3515796c8dcSSimon Schubert 3525796c8dcSSimon Schubert /* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A 3535796c8dcSSimon Schubert NULL format specifier was allowed as of gcc 3.3. */ 3545796c8dcSSimon Schubert #ifndef ATTRIBUTE_NULL_PRINTF 3555796c8dcSSimon Schubert # if (GCC_VERSION >= 3003) 3565796c8dcSSimon Schubert # define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) 3575796c8dcSSimon Schubert # else 3585796c8dcSSimon Schubert # define ATTRIBUTE_NULL_PRINTF(m, n) 3595796c8dcSSimon Schubert # endif /* GNUC >= 3.3 */ 3605796c8dcSSimon Schubert # define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2) 3615796c8dcSSimon Schubert # define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3) 3625796c8dcSSimon Schubert # define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4) 3635796c8dcSSimon Schubert # define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5) 3645796c8dcSSimon Schubert # define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6) 3655796c8dcSSimon Schubert #endif /* ATTRIBUTE_NULL_PRINTF */ 3665796c8dcSSimon Schubert 3675796c8dcSSimon Schubert /* Attribute `sentinel' was valid as of gcc 3.5. */ 3685796c8dcSSimon Schubert #ifndef ATTRIBUTE_SENTINEL 3695796c8dcSSimon Schubert # if (GCC_VERSION >= 3005) 3705796c8dcSSimon Schubert # define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__)) 3715796c8dcSSimon Schubert # else 3725796c8dcSSimon Schubert # define ATTRIBUTE_SENTINEL 3735796c8dcSSimon Schubert # endif /* GNUC >= 3.5 */ 3745796c8dcSSimon Schubert #endif /* ATTRIBUTE_SENTINEL */ 3755796c8dcSSimon Schubert 3765796c8dcSSimon Schubert 3775796c8dcSSimon Schubert #ifndef ATTRIBUTE_ALIGNED_ALIGNOF 3785796c8dcSSimon Schubert # if (GCC_VERSION >= 3000) 3795796c8dcSSimon Schubert # define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m)))) 3805796c8dcSSimon Schubert # else 3815796c8dcSSimon Schubert # define ATTRIBUTE_ALIGNED_ALIGNOF(m) 3825796c8dcSSimon Schubert # endif /* GNUC >= 3.0 */ 3835796c8dcSSimon Schubert #endif /* ATTRIBUTE_ALIGNED_ALIGNOF */ 3845796c8dcSSimon Schubert 3855796c8dcSSimon Schubert /* Useful for structures whose layout must much some binary specification 3865796c8dcSSimon Schubert regardless of the alignment and padding qualities of the compiler. */ 3875796c8dcSSimon Schubert #ifndef ATTRIBUTE_PACKED 3885796c8dcSSimon Schubert # define ATTRIBUTE_PACKED __attribute__ ((packed)) 3895796c8dcSSimon Schubert #endif 3905796c8dcSSimon Schubert 3915796c8dcSSimon Schubert /* Attribute `hot' and `cold' was valid as of gcc 4.3. */ 3925796c8dcSSimon Schubert #ifndef ATTRIBUTE_COLD 3935796c8dcSSimon Schubert # if (GCC_VERSION >= 4003) 3945796c8dcSSimon Schubert # define ATTRIBUTE_COLD __attribute__ ((__cold__)) 3955796c8dcSSimon Schubert # else 3965796c8dcSSimon Schubert # define ATTRIBUTE_COLD 3975796c8dcSSimon Schubert # endif /* GNUC >= 4.3 */ 3985796c8dcSSimon Schubert #endif /* ATTRIBUTE_COLD */ 3995796c8dcSSimon Schubert #ifndef ATTRIBUTE_HOT 4005796c8dcSSimon Schubert # if (GCC_VERSION >= 4003) 4015796c8dcSSimon Schubert # define ATTRIBUTE_HOT __attribute__ ((__hot__)) 4025796c8dcSSimon Schubert # else 4035796c8dcSSimon Schubert # define ATTRIBUTE_HOT 4045796c8dcSSimon Schubert # endif /* GNUC >= 4.3 */ 4055796c8dcSSimon Schubert #endif /* ATTRIBUTE_HOT */ 4065796c8dcSSimon Schubert 4075796c8dcSSimon Schubert /* We use __extension__ in some places to suppress -pedantic warnings 4085796c8dcSSimon Schubert about GCC extensions. This feature didn't work properly before 4095796c8dcSSimon Schubert gcc 2.8. */ 4105796c8dcSSimon Schubert #if GCC_VERSION < 2008 4115796c8dcSSimon Schubert #define __extension__ 4125796c8dcSSimon Schubert #endif 4135796c8dcSSimon Schubert 4145796c8dcSSimon Schubert /* This is used to declare a const variable which should be visible 4155796c8dcSSimon Schubert outside of the current compilation unit. Use it as 4165796c8dcSSimon Schubert EXPORTED_CONST int i = 1; 4175796c8dcSSimon Schubert This is because the semantics of const are different in C and C++. 4185796c8dcSSimon Schubert "extern const" is permitted in C but it looks strange, and gcc 4195796c8dcSSimon Schubert warns about it when -Wc++-compat is not used. */ 4205796c8dcSSimon Schubert #ifdef __cplusplus 4215796c8dcSSimon Schubert #define EXPORTED_CONST extern const 4225796c8dcSSimon Schubert #else 4235796c8dcSSimon Schubert #define EXPORTED_CONST const 4245796c8dcSSimon Schubert #endif 4255796c8dcSSimon Schubert 426a45ae5f8SJohn Marino /* Be conservative and only use enum bitfields with C++ or GCC. 427a45ae5f8SJohn Marino FIXME: provide a complete autoconf test for buggy enum bitfields. */ 428a45ae5f8SJohn Marino 429a45ae5f8SJohn Marino #ifdef __cplusplus 430a45ae5f8SJohn Marino #define ENUM_BITFIELD(TYPE) enum TYPE 431a45ae5f8SJohn Marino #elif (GCC_VERSION > 2000) 432a45ae5f8SJohn Marino #define ENUM_BITFIELD(TYPE) __extension__ enum TYPE 433a45ae5f8SJohn Marino #else 434a45ae5f8SJohn Marino #define ENUM_BITFIELD(TYPE) unsigned int 435a45ae5f8SJohn Marino #endif 436a45ae5f8SJohn Marino 4375796c8dcSSimon Schubert #ifdef __cplusplus 4385796c8dcSSimon Schubert } 4395796c8dcSSimon Schubert #endif 4405796c8dcSSimon Schubert 4415796c8dcSSimon Schubert #endif /* ansidecl.h */ 442