| 1 | /* ANSI and traditional C compatability macros | 
|---|
| 2 | Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000 | 
|---|
| 3 | Free Software Foundation, Inc. | 
|---|
| 4 | This file is part of the GNU C Library. | 
|---|
| 5 |  | 
|---|
| 6 | This program is free software; you can redistribute it and/or modify | 
|---|
| 7 | it under the terms of the GNU General Public License as published by | 
|---|
| 8 | the Free Software Foundation; either version 2 of the License, or | 
|---|
| 9 | (at your option) any later version. | 
|---|
| 10 |  | 
|---|
| 11 | This program is distributed in the hope that it will be useful, | 
|---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 14 | GNU General Public License for more details. | 
|---|
| 15 |  | 
|---|
| 16 | You should have received a copy of the GNU General Public License | 
|---|
| 17 | along with this program; if not, write to the Free Software | 
|---|
| 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */ | 
|---|
| 19 |  | 
|---|
| 20 | /* ANSI and traditional C compatibility macros | 
|---|
| 21 |  | 
|---|
| 22 | ANSI C is assumed if __STDC__ is #defined. | 
|---|
| 23 |  | 
|---|
| 24 | Macro        ANSI C definition       Traditional C definition | 
|---|
| 25 | -----        ---- - ----------       ----------- - ---------- | 
|---|
| 26 | PTR          `void *'                `char *' | 
|---|
| 27 | LONG_DOUBLE  `long double'           `double' | 
|---|
| 28 | VOLATILE     `volatile'              `' | 
|---|
| 29 | SIGNED       `signed'                `' | 
|---|
| 30 | PTRCONST     `void *const'           `char *' | 
|---|
| 31 | ANSI_PROTOTYPES  1                   not defined | 
|---|
| 32 |  | 
|---|
| 33 | CONST is also defined, but is obsolete.  Just use const. | 
|---|
| 34 |  | 
|---|
| 35 | obsolete --     DEFUN (name, arglist, args) | 
|---|
| 36 |  | 
|---|
| 37 | Defines function NAME. | 
|---|
| 38 |  | 
|---|
| 39 | ARGLIST lists the arguments, separated by commas and enclosed in | 
|---|
| 40 | parentheses.  ARGLIST becomes the argument list in traditional C. | 
|---|
| 41 |  | 
|---|
| 42 | ARGS list the arguments with their types.  It becomes a prototype in | 
|---|
| 43 | ANSI C, and the type declarations in traditional C.  Arguments should | 
|---|
| 44 | be separated with `AND'.  For functions with a variable number of | 
|---|
| 45 | arguments, the last thing listed should be `DOTS'. | 
|---|
| 46 |  | 
|---|
| 47 | obsolete --     DEFUN_VOID (name) | 
|---|
| 48 |  | 
|---|
| 49 | Defines a function NAME, which takes no arguments. | 
|---|
| 50 |  | 
|---|
| 51 | obsolete --     EXFUN (name, (prototype))    -- obsolete. | 
|---|
| 52 |  | 
|---|
| 53 | Replaced by PARAMS.  Do not use; will disappear someday soon. | 
|---|
| 54 | Was used in external function declarations. | 
|---|
| 55 | In ANSI C it is `NAME PROTOTYPE' (so PROTOTYPE should be enclosed in | 
|---|
| 56 | parentheses).  In traditional C it is `NAME()'. | 
|---|
| 57 | For a function that takes no arguments, PROTOTYPE should be `(void)'. | 
|---|
| 58 |  | 
|---|
| 59 | obsolete --     PROTO (type, name, (prototype)    -- obsolete. | 
|---|
| 60 |  | 
|---|
| 61 | This one has also been replaced by PARAMS.  Do not use. | 
|---|
| 62 |  | 
|---|
| 63 | PARAMS ((args)) | 
|---|
| 64 |  | 
|---|
| 65 | We could use the EXFUN macro to handle prototype declarations, but | 
|---|
| 66 | the name is misleading and the result is ugly.  So we just define a | 
|---|
| 67 | simple macro to handle the parameter lists, as in: | 
|---|
| 68 |  | 
|---|
| 69 | static int foo PARAMS ((int, char)); | 
|---|
| 70 |  | 
|---|
| 71 | This produces:  `static int foo();' or `static int foo (int, char);' | 
|---|
| 72 |  | 
|---|
| 73 | EXFUN would have done it like this: | 
|---|
| 74 |  | 
|---|
| 75 | static int EXFUN (foo, (int, char)); | 
|---|
| 76 |  | 
|---|
| 77 | but the function is not external...and it's hard to visually parse | 
|---|
| 78 | the function name out of the mess.   EXFUN should be considered | 
|---|
| 79 | obsolete; new code should be written to use PARAMS. | 
|---|
| 80 |  | 
|---|
| 81 | DOTS is also obsolete. | 
|---|
| 82 |  | 
|---|
| 83 | Examples: | 
|---|
| 84 |  | 
|---|
| 85 | extern int printf PARAMS ((const char *format, ...)); | 
|---|
| 86 | */ | 
|---|
| 87 |  | 
|---|
| 88 | #ifndef _ANSIDECL_H | 
|---|
| 89 |  | 
|---|
| 90 | #define _ANSIDECL_H     1 | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 | /* Every source file includes this file, | 
|---|
| 94 | so they will all get the switch for lint.  */ | 
|---|
| 95 | /* LINTLIBRARY */ | 
|---|
| 96 |  | 
|---|
| 97 |  | 
|---|
| 98 | #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) | 
|---|
| 99 | /* All known AIX compilers implement these things (but don't always | 
|---|
| 100 | define __STDC__).  The RISC/OS MIPS compiler defines these things | 
|---|
| 101 | in SVR4 mode, but does not define __STDC__.  */ | 
|---|
| 102 |  | 
|---|
| 103 | #define PTR             void * | 
|---|
| 104 | #define PTRCONST        void *CONST | 
|---|
| 105 | #define LONG_DOUBLE     long double | 
|---|
| 106 |  | 
|---|
| 107 | #ifndef IN_GCC | 
|---|
| 108 | #define AND             , | 
|---|
| 109 | #define NOARGS          void | 
|---|
| 110 | #define VOLATILE        volatile | 
|---|
| 111 | #define SIGNED          signed | 
|---|
| 112 | #endif /* ! IN_GCC */ | 
|---|
| 113 |  | 
|---|
| 114 | #define PARAMS(paramlist)               paramlist | 
|---|
| 115 | #define ANSI_PROTOTYPES                 1 | 
|---|
| 116 |  | 
|---|
| 117 | #define VPARAMS(ARGS)                   ARGS | 
|---|
| 118 | #define VA_START(va_list,var)           va_start(va_list,var) | 
|---|
| 119 |  | 
|---|
| 120 | /* These are obsolete.  Do not use.  */ | 
|---|
| 121 | #ifndef IN_GCC | 
|---|
| 122 | #define CONST                           const | 
|---|
| 123 | #define DOTS                            , ... | 
|---|
| 124 | #define PROTO(type, name, arglist)      type name arglist | 
|---|
| 125 | #define EXFUN(name, proto)              name proto | 
|---|
| 126 | #define DEFUN(name, arglist, args)      name(args) | 
|---|
| 127 | #define DEFUN_VOID(name)                name(void) | 
|---|
| 128 | #endif /* ! IN_GCC */ | 
|---|
| 129 |  | 
|---|
| 130 | #else   /* Not ANSI C.  */ | 
|---|
| 131 |  | 
|---|
| 132 | #define PTR             char * | 
|---|
| 133 | #define PTRCONST        PTR | 
|---|
| 134 | #define LONG_DOUBLE     double | 
|---|
| 135 |  | 
|---|
| 136 | #ifndef IN_GCC | 
|---|
| 137 | #define AND             ; | 
|---|
| 138 | #define NOARGS | 
|---|
| 139 | #define VOLATILE | 
|---|
| 140 | #define SIGNED | 
|---|
| 141 | #endif /* !IN_GCC */ | 
|---|
| 142 |  | 
|---|
| 143 | #ifndef const /* some systems define it in header files for non-ansi mode */ | 
|---|
| 144 | #define const | 
|---|
| 145 | #endif | 
|---|
| 146 |  | 
|---|
| 147 | #define PARAMS(paramlist)               () | 
|---|
| 148 |  | 
|---|
| 149 | #define VPARAMS(ARGS)                   (va_alist) va_dcl | 
|---|
| 150 | #define VA_START(va_list,var)           va_start(va_list) | 
|---|
| 151 |  | 
|---|
| 152 | /* These are obsolete.  Do not use.  */ | 
|---|
| 153 | #ifndef IN_GCC | 
|---|
| 154 | #define CONST | 
|---|
| 155 | #define DOTS | 
|---|
| 156 | #define PROTO(type, name, arglist)      type name () | 
|---|
| 157 | #define EXFUN(name, proto)              name() | 
|---|
| 158 | #define DEFUN(name, arglist, args)      name arglist args; | 
|---|
| 159 | #define DEFUN_VOID(name)                name() | 
|---|
| 160 | #endif /* ! IN_GCC */ | 
|---|
| 161 |  | 
|---|
| 162 | #endif  /* ANSI C.  */ | 
|---|
| 163 |  | 
|---|
| 164 |  | 
|---|
| 165 | /* Using MACRO(x,y) in cpp #if conditionals does not work with some | 
|---|
| 166 | older preprocessors.  Thus we can't define something like this: | 
|---|
| 167 |  | 
|---|
| 168 | #define HAVE_GCC_VERSION(MAJOR, MINOR) \ | 
|---|
| 169 | (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR))) | 
|---|
| 170 |  | 
|---|
| 171 | and then test "#if HAVE_GCC_VERSION(2,7)". | 
|---|
| 172 |  | 
|---|
| 173 | So instead we use the macro below and test it against specific values.  */ | 
|---|
| 174 |  | 
|---|
| 175 | /* This macro simplifies testing whether we are using gcc, and if it | 
|---|
| 176 | is of a particular minimum version. (Both major & minor numbers are | 
|---|
| 177 | significant.)  This macro will evaluate to 0 if we are not using | 
|---|
| 178 | gcc at all.  */ | 
|---|
| 179 | #ifndef GCC_VERSION | 
|---|
| 180 | #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) | 
|---|
| 181 | #endif /* GCC_VERSION */ | 
|---|
| 182 |  | 
|---|
| 183 | /* Define macros for some gcc attributes.  This permits us to use the | 
|---|
| 184 | macros freely, and know that they will come into play for the | 
|---|
| 185 | version of gcc in which they are supported.  */ | 
|---|
| 186 |  | 
|---|
| 187 | #if (GCC_VERSION < 2007) | 
|---|
| 188 | # define __attribute__(x) | 
|---|
| 189 | #endif | 
|---|
| 190 |  | 
|---|
| 191 | /* Attribute __malloc__ on functions was valid as of gcc 2.96. */ | 
|---|
| 192 | #ifndef ATTRIBUTE_MALLOC | 
|---|
| 193 | # if (GCC_VERSION >= 2096) | 
|---|
| 194 | #  define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) | 
|---|
| 195 | # else | 
|---|
| 196 | #  define ATTRIBUTE_MALLOC | 
|---|
| 197 | # endif /* GNUC >= 2.96 */ | 
|---|
| 198 | #endif /* ATTRIBUTE_MALLOC */ | 
|---|
| 199 |  | 
|---|
| 200 | /* Attributes on labels were valid as of gcc 2.93. */ | 
|---|
| 201 | #ifndef ATTRIBUTE_UNUSED_LABEL | 
|---|
| 202 | # if (GCC_VERSION >= 2093) | 
|---|
| 203 | #  define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED | 
|---|
| 204 | # else | 
|---|
| 205 | #  define ATTRIBUTE_UNUSED_LABEL | 
|---|
| 206 | # endif /* GNUC >= 2.93 */ | 
|---|
| 207 | #endif /* ATTRIBUTE_UNUSED_LABEL */ | 
|---|
| 208 |  | 
|---|
| 209 | #ifndef ATTRIBUTE_UNUSED | 
|---|
| 210 | #define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | 
|---|
| 211 | #endif /* ATTRIBUTE_UNUSED */ | 
|---|
| 212 |  | 
|---|
| 213 | #ifndef ATTRIBUTE_NORETURN | 
|---|
| 214 | #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | 
|---|
| 215 | #endif /* ATTRIBUTE_NORETURN */ | 
|---|
| 216 |  | 
|---|
| 217 | #ifndef ATTRIBUTE_PRINTF | 
|---|
| 218 | #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) | 
|---|
| 219 | #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2) | 
|---|
| 220 | #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3) | 
|---|
| 221 | #define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4) | 
|---|
| 222 | #define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5) | 
|---|
| 223 | #define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6) | 
|---|
| 224 | #endif /* ATTRIBUTE_PRINTF */ | 
|---|
| 225 |  | 
|---|
| 226 | /* We use __extension__ in some places to suppress -pedantic warnings | 
|---|
| 227 | about GCC extensions.  This feature didn't work properly before | 
|---|
| 228 | gcc 2.8.  */ | 
|---|
| 229 | #if GCC_VERSION < 2008 | 
|---|
| 230 | #define __extension__ | 
|---|
| 231 | #endif | 
|---|
| 232 |  | 
|---|
| 233 | #endif  /* ansidecl.h   */ | 
|---|