1169695Skan/* ANSI and traditional C compatability macros 2169695Skan Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 3169695Skan Free Software Foundation, Inc. 4169695Skan This file is part of the GNU C Library. 5169695Skan 6169695SkanThis program is free software; you can redistribute it and/or modify 7169695Skanit under the terms of the GNU General Public License as published by 8169695Skanthe Free Software Foundation; either version 2 of the License, or 9169695Skan(at your option) any later version. 10169695Skan 11169695SkanThis program is distributed in the hope that it will be useful, 12169695Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of 13169695SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14169695SkanGNU General Public License for more details. 15169695Skan 16169695SkanYou should have received a copy of the GNU General Public License 17169695Skanalong with this program; if not, write to the Free Software 18169695SkanFoundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 19169695Skan 20169695Skan/* ANSI and traditional C compatibility macros 21169695Skan 22169695Skan ANSI C is assumed if __STDC__ is #defined. 23169695Skan 24169695Skan Macro ANSI C definition Traditional C definition 25169695Skan ----- ---- - ---------- ----------- - ---------- 26169695Skan ANSI_PROTOTYPES 1 not defined 27169695Skan PTR `void *' `char *' 28169695Skan PTRCONST `void *const' `char *' 29169695Skan LONG_DOUBLE `long double' `double' 30169695Skan const not defined `' 31169695Skan volatile not defined `' 32169695Skan signed not defined `' 33169695Skan VA_START(ap, var) va_start(ap, var) va_start(ap) 34169695Skan 35169695Skan Note that it is safe to write "void foo();" indicating a function 36169695Skan with no return value, in all K+R compilers we have been able to test. 37169695Skan 38169695Skan For declaring functions with prototypes, we also provide these: 39169695Skan 40169695Skan PARAMS ((prototype)) 41169695Skan -- for functions which take a fixed number of arguments. Use this 42169695Skan when declaring the function. When defining the function, write a 43169695Skan K+R style argument list. For example: 44169695Skan 45169695Skan char *strcpy PARAMS ((char *dest, char *source)); 46169695Skan ... 47169695Skan char * 48169695Skan strcpy (dest, source) 49169695Skan char *dest; 50169695Skan char *source; 51169695Skan { ... } 52169695Skan 53169695Skan 54169695Skan VPARAMS ((prototype, ...)) 55169695Skan -- for functions which take a variable number of arguments. Use 56169695Skan PARAMS to declare the function, VPARAMS to define it. For example: 57169695Skan 58169695Skan int printf PARAMS ((const char *format, ...)); 59169695Skan ... 60169695Skan int 61169695Skan printf VPARAMS ((const char *format, ...)) 62169695Skan { 63169695Skan ... 64169695Skan } 65169695Skan 66169695Skan For writing functions which take variable numbers of arguments, we 67169695Skan also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros. These 68169695Skan hide the differences between K+R <varargs.h> and C89 <stdarg.h> more 69169695Skan thoroughly than the simple VA_START() macro mentioned above. 70169695Skan 71169695Skan VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end. 72169695Skan Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls 73169695Skan corresponding to the list of fixed arguments. Then use va_arg 74169695Skan normally to get the variable arguments, or pass your va_list object 75169695Skan around. You do not declare the va_list yourself; VA_OPEN does it 76169695Skan for you. 77169695Skan 78169695Skan Here is a complete example: 79169695Skan 80169695Skan int 81169695Skan printf VPARAMS ((const char *format, ...)) 82169695Skan { 83169695Skan int result; 84169695Skan 85169695Skan VA_OPEN (ap, format); 86169695Skan VA_FIXEDARG (ap, const char *, format); 87169695Skan 88169695Skan result = vfprintf (stdout, format, ap); 89169695Skan VA_CLOSE (ap); 90169695Skan 91169695Skan return result; 92169695Skan } 93169695Skan 94169695Skan 95169695Skan You can declare variables either before or after the VA_OPEN, 96169695Skan VA_FIXEDARG sequence. Also, VA_OPEN and VA_CLOSE are the beginning 97169695Skan and end of a block. They must appear at the same nesting level, 98169695Skan and any variables declared after VA_OPEN go out of scope at 99169695Skan VA_CLOSE. Unfortunately, with a K+R compiler, that includes the 100169695Skan argument list. You can have multiple instances of VA_OPEN/VA_CLOSE 101169695Skan pairs in a single function in case you need to traverse the 102169695Skan argument list more than once. 103169695Skan 104169695Skan For ease of writing code which uses GCC extensions but needs to be 105169695Skan portable to other compilers, we provide the GCC_VERSION macro that 106169695Skan simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various 107169695Skan wrappers around __attribute__. Also, __extension__ will be #defined 108169695Skan to nothing if it doesn't work. See below. 109169695Skan 110169695Skan This header also defines a lot of obsolete macros: 111169695Skan CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID, 112169695Skan AND, DOTS, NOARGS. Don't use them. */ 113169695Skan 114169695Skan#ifndef _ANSIDECL_H 115169695Skan#define _ANSIDECL_H 1 116169695Skan 117169695Skan/* Every source file includes this file, 118169695Skan so they will all get the switch for lint. */ 119169695Skan/* LINTLIBRARY */ 120169695Skan 121169695Skan/* Using MACRO(x,y) in cpp #if conditionals does not work with some 122169695Skan older preprocessors. Thus we can't define something like this: 123169695Skan 124169695Skan#define HAVE_GCC_VERSION(MAJOR, MINOR) \ 125169695Skan (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR))) 126169695Skan 127169695Skanand then test "#if HAVE_GCC_VERSION(2,7)". 128169695Skan 129169695SkanSo instead we use the macro below and test it against specific values. */ 130169695Skan 131169695Skan/* This macro simplifies testing whether we are using gcc, and if it 132169695Skan is of a particular minimum version. (Both major & minor numbers are 133169695Skan significant.) This macro will evaluate to 0 if we are not using 134169695Skan gcc at all. */ 135169695Skan#ifndef GCC_VERSION 136169695Skan#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) 137169695Skan#endif /* GCC_VERSION */ 138169695Skan 139169695Skan#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) || (defined(__alpha) && defined(__cplusplus)) 140169695Skan/* All known AIX compilers implement these things (but don't always 141169695Skan define __STDC__). The RISC/OS MIPS compiler defines these things 142169695Skan in SVR4 mode, but does not define __STDC__. */ 143169695Skan/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other 144169695Skan C++ compilers, does not define __STDC__, though it acts as if this 145169695Skan was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */ 146169695Skan 147169695Skan#define ANSI_PROTOTYPES 1 148169695Skan#define PTR void * 149169695Skan#define PTRCONST void *const 150169695Skan#define LONG_DOUBLE long double 151169695Skan 152169695Skan/* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in 153169695Skan a #ifndef. */ 154169695Skan#ifndef PARAMS 155169695Skan#define PARAMS(ARGS) ARGS 156169695Skan#endif 157169695Skan 158169695Skan#define VPARAMS(ARGS) ARGS 159169695Skan#define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR) 160169695Skan 161169695Skan/* variadic function helper macros */ 162169695Skan/* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's 163169695Skan use without inhibiting further decls and without declaring an 164169695Skan actual variable. */ 165169695Skan#define VA_OPEN(AP, VAR) { va_list AP; va_start(AP, VAR); { struct Qdmy 166169695Skan#define VA_CLOSE(AP) } va_end(AP); } 167169695Skan#define VA_FIXEDARG(AP, T, N) struct Qdmy 168169695Skan 169169695Skan#undef const 170169695Skan#undef volatile 171169695Skan#undef signed 172169695Skan 173169695Skan/* inline requires special treatment; it's in C99, and GCC >=2.7 supports 174169695Skan it too, but it's not in C89. */ 175169695Skan#undef inline 176169695Skan#if __STDC_VERSION__ > 199901L 177169695Skan/* it's a keyword */ 178169695Skan#else 179169695Skan# if GCC_VERSION >= 2007 180169695Skan# define inline __inline__ /* __inline__ prevents -pedantic warnings */ 181169695Skan# else 182169695Skan# define inline /* nothing */ 183169695Skan# endif 184169695Skan#endif 185169695Skan 186169695Skan/* These are obsolete. Do not use. */ 187169695Skan#ifndef IN_GCC 188169695Skan#define CONST const 189169695Skan#define VOLATILE volatile 190169695Skan#define SIGNED signed 191169695Skan 192169695Skan#define PROTO(type, name, arglist) type name arglist 193169695Skan#define EXFUN(name, proto) name proto 194169695Skan#define DEFUN(name, arglist, args) name(args) 195169695Skan#define DEFUN_VOID(name) name(void) 196169695Skan#define AND , 197169695Skan#define DOTS , ... 198169695Skan#define NOARGS void 199169695Skan#endif /* ! IN_GCC */ 200169695Skan 201169695Skan#else /* Not ANSI C. */ 202169695Skan 203169695Skan#undef ANSI_PROTOTYPES 204169695Skan#define PTR char * 205169695Skan#define PTRCONST PTR 206169695Skan#define LONG_DOUBLE double 207169695Skan 208169695Skan#define PARAMS(args) () 209169695Skan#define VPARAMS(args) (va_alist) va_dcl 210169695Skan#define VA_START(va_list, var) va_start(va_list) 211169695Skan 212169695Skan#define VA_OPEN(AP, VAR) { va_list AP; va_start(AP); { struct Qdmy 213169695Skan#define VA_CLOSE(AP) } va_end(AP); } 214169695Skan#define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE) 215169695Skan 216169695Skan/* some systems define these in header files for non-ansi mode */ 217169695Skan#undef const 218169695Skan#undef volatile 219169695Skan#undef signed 220169695Skan#undef inline 221169695Skan#define const 222169695Skan#define volatile 223169695Skan#define signed 224169695Skan#define inline 225169695Skan 226169695Skan#ifndef IN_GCC 227169695Skan#define CONST 228169695Skan#define VOLATILE 229169695Skan#define SIGNED 230169695Skan 231169695Skan#define PROTO(type, name, arglist) type name () 232169695Skan#define EXFUN(name, proto) name() 233169695Skan#define DEFUN(name, arglist, args) name arglist args; 234169695Skan#define DEFUN_VOID(name) name() 235169695Skan#define AND ; 236169695Skan#define DOTS 237169695Skan#define NOARGS 238169695Skan#endif /* ! IN_GCC */ 239169695Skan 240169695Skan#endif /* ANSI C. */ 241169695Skan 242169695Skan/* Define macros for some gcc attributes. This permits us to use the 243169695Skan macros freely, and know that they will come into play for the 244169695Skan version of gcc in which they are supported. */ 245169695Skan 246169695Skan#if (GCC_VERSION < 2007) 247169695Skan# define __attribute__(x) 248169695Skan#endif 249169695Skan 250169695Skan/* Attribute __malloc__ on functions was valid as of gcc 2.96. */ 251169695Skan#ifndef ATTRIBUTE_MALLOC 252169695Skan# if (GCC_VERSION >= 2096) 253169695Skan# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) 254169695Skan# else 255169695Skan# define ATTRIBUTE_MALLOC 256169695Skan# endif /* GNUC >= 2.96 */ 257169695Skan#endif /* ATTRIBUTE_MALLOC */ 258169695Skan 259169695Skan/* Attributes on labels were valid as of gcc 2.93. */ 260169695Skan#ifndef ATTRIBUTE_UNUSED_LABEL 261169695Skan# if (!defined (__cplusplus) && GCC_VERSION >= 2093) 262169695Skan# define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED 263169695Skan# else 264169695Skan# define ATTRIBUTE_UNUSED_LABEL 265169695Skan# endif /* !__cplusplus && GNUC >= 2.93 */ 266169695Skan#endif /* ATTRIBUTE_UNUSED_LABEL */ 267169695Skan 268169695Skan#ifndef ATTRIBUTE_UNUSED 269169695Skan#define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 270169695Skan#endif /* ATTRIBUTE_UNUSED */ 271169695Skan 272169695Skan/* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the 273169695Skan identifier name. */ 274169695Skan#if ! defined(__cplusplus) || (GCC_VERSION >= 3004) 275169695Skan# define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED 276169695Skan#else /* !__cplusplus || GNUC >= 3.4 */ 277169695Skan# define ARG_UNUSED(NAME) NAME 278169695Skan#endif /* !__cplusplus || GNUC >= 3.4 */ 279169695Skan 280169695Skan#ifndef ATTRIBUTE_NORETURN 281169695Skan#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) 282169695Skan#endif /* ATTRIBUTE_NORETURN */ 283169695Skan 284169695Skan/* Attribute `nonnull' was valid as of gcc 3.3. */ 285169695Skan#ifndef ATTRIBUTE_NONNULL 286169695Skan# if (GCC_VERSION >= 3003) 287169695Skan# define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m))) 288169695Skan# else 289169695Skan# define ATTRIBUTE_NONNULL(m) 290169695Skan# endif /* GNUC >= 3.3 */ 291169695Skan#endif /* ATTRIBUTE_NONNULL */ 292169695Skan 293169695Skan/* Attribute `pure' was valid as of gcc 3.0. */ 294169695Skan#ifndef ATTRIBUTE_PURE 295169695Skan# if (GCC_VERSION >= 3000) 296169695Skan# define ATTRIBUTE_PURE __attribute__ ((__pure__)) 297169695Skan# else 298169695Skan# define ATTRIBUTE_PURE 299169695Skan# endif /* GNUC >= 3.0 */ 300169695Skan#endif /* ATTRIBUTE_PURE */ 301169695Skan 302169695Skan/* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL. 303169695Skan This was the case for the `printf' format attribute by itself 304169695Skan before GCC 3.3, but as of 3.3 we need to add the `nonnull' 305169695Skan attribute to retain this behavior. */ 306169695Skan#ifndef ATTRIBUTE_PRINTF 307169695Skan#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m) 308169695Skan#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2) 309169695Skan#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3) 310169695Skan#define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4) 311169695Skan#define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5) 312169695Skan#define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6) 313169695Skan#endif /* ATTRIBUTE_PRINTF */ 314169695Skan 315169695Skan/* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on 316169695Skan a function pointer. Format attributes were allowed on function 317169695Skan pointers as of gcc 3.1. */ 318169695Skan#ifndef ATTRIBUTE_FPTR_PRINTF 319169695Skan# if (GCC_VERSION >= 3001) 320169695Skan# define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n) 321169695Skan# else 322169695Skan# define ATTRIBUTE_FPTR_PRINTF(m, n) 323169695Skan# endif /* GNUC >= 3.1 */ 324169695Skan# define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2) 325169695Skan# define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3) 326169695Skan# define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4) 327169695Skan# define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5) 328169695Skan# define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6) 329169695Skan#endif /* ATTRIBUTE_FPTR_PRINTF */ 330169695Skan 331169695Skan/* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A 332169695Skan NULL format specifier was allowed as of gcc 3.3. */ 333169695Skan#ifndef ATTRIBUTE_NULL_PRINTF 334169695Skan# if (GCC_VERSION >= 3003) 335169695Skan# define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) 336169695Skan# else 337169695Skan# define ATTRIBUTE_NULL_PRINTF(m, n) 338169695Skan# endif /* GNUC >= 3.3 */ 339169695Skan# define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2) 340169695Skan# define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3) 341169695Skan# define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4) 342169695Skan# define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5) 343169695Skan# define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6) 344169695Skan#endif /* ATTRIBUTE_NULL_PRINTF */ 345169695Skan 346169695Skan/* Attribute `sentinel' was valid as of gcc 3.5. */ 347169695Skan#ifndef ATTRIBUTE_SENTINEL 348169695Skan# if (GCC_VERSION >= 3005) 349169695Skan# define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__)) 350169695Skan# else 351169695Skan# define ATTRIBUTE_SENTINEL 352169695Skan# endif /* GNUC >= 3.5 */ 353169695Skan#endif /* ATTRIBUTE_SENTINEL */ 354169695Skan 355169695Skan 356169695Skan#ifndef ATTRIBUTE_ALIGNED_ALIGNOF 357169695Skan# if (GCC_VERSION >= 3000) 358169695Skan# define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m)))) 359169695Skan# else 360169695Skan# define ATTRIBUTE_ALIGNED_ALIGNOF(m) 361169695Skan# endif /* GNUC >= 3.0 */ 362169695Skan#endif /* ATTRIBUTE_ALIGNED_ALIGNOF */ 363169695Skan 364169695Skan/* We use __extension__ in some places to suppress -pedantic warnings 365169695Skan about GCC extensions. This feature didn't work properly before 366169695Skan gcc 2.8. */ 367169695Skan#if GCC_VERSION < 2008 368169695Skan#define __extension__ 369169695Skan#endif 370169695Skan 371169695Skan#endif /* ansidecl.h */ 372