Back to index

cell-binutils  2.17cvs20070401
ansidecl.h
Go to the documentation of this file.
00001 /* ANSI and traditional C compatability macros
00002    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006 This program is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with this program; if not, write to the Free Software
00018 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00019 
00020 /* ANSI and traditional C compatibility macros
00021 
00022    ANSI C is assumed if __STDC__ is #defined.
00023 
00024    Macro             ANSI C definition    Traditional C definition
00025    -----             ---- - ----------    ----------- - ----------
00026    ANSI_PROTOTYPES   1                    not defined
00027    PTR               `void *'             `char *'
00028    PTRCONST          `void *const'        `char *'
00029    LONG_DOUBLE              `long double'        `double'
00030    const             not defined          `'
00031    volatile          not defined          `'
00032    signed            not defined          `'
00033    VA_START(ap, var) va_start(ap, var)    va_start(ap)
00034 
00035    Note that it is safe to write "void foo();" indicating a function
00036    with no return value, in all K+R compilers we have been able to test.
00037 
00038    For declaring functions with prototypes, we also provide these:
00039 
00040    PARAMS ((prototype))
00041    -- for functions which take a fixed number of arguments.  Use this
00042    when declaring the function.  When defining the function, write a
00043    K+R style argument list.  For example:
00044 
00045        char *strcpy PARAMS ((char *dest, char *source));
00046        ...
00047        char *
00048        strcpy (dest, source)
00049             char *dest;
00050             char *source;
00051        { ... }
00052 
00053 
00054    VPARAMS ((prototype, ...))
00055    -- for functions which take a variable number of arguments.  Use
00056    PARAMS to declare the function, VPARAMS to define it.  For example:
00057 
00058        int printf PARAMS ((const char *format, ...));
00059        ...
00060        int
00061        printf VPARAMS ((const char *format, ...))
00062        {
00063           ...
00064        }
00065 
00066    For writing functions which take variable numbers of arguments, we
00067    also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros.  These
00068    hide the differences between K+R <varargs.h> and C89 <stdarg.h> more
00069    thoroughly than the simple VA_START() macro mentioned above.
00070 
00071    VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end.
00072    Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls
00073    corresponding to the list of fixed arguments.  Then use va_arg
00074    normally to get the variable arguments, or pass your va_list object
00075    around.  You do not declare the va_list yourself; VA_OPEN does it
00076    for you.
00077 
00078    Here is a complete example:
00079 
00080        int
00081        printf VPARAMS ((const char *format, ...))
00082        {
00083           int result;
00084 
00085           VA_OPEN (ap, format);
00086           VA_FIXEDARG (ap, const char *, format);
00087 
00088           result = vfprintf (stdout, format, ap);
00089           VA_CLOSE (ap);
00090 
00091           return result;
00092        }
00093 
00094 
00095    You can declare variables either before or after the VA_OPEN,
00096    VA_FIXEDARG sequence.  Also, VA_OPEN and VA_CLOSE are the beginning
00097    and end of a block.  They must appear at the same nesting level,
00098    and any variables declared after VA_OPEN go out of scope at
00099    VA_CLOSE.  Unfortunately, with a K+R compiler, that includes the
00100    argument list.  You can have multiple instances of VA_OPEN/VA_CLOSE
00101    pairs in a single function in case you need to traverse the
00102    argument list more than once.
00103 
00104    For ease of writing code which uses GCC extensions but needs to be
00105    portable to other compilers, we provide the GCC_VERSION macro that
00106    simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
00107    wrappers around __attribute__.  Also, __extension__ will be #defined
00108    to nothing if it doesn't work.  See below.
00109 
00110    This header also defines a lot of obsolete macros:
00111    CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID,
00112    AND, DOTS, NOARGS.  Don't use them.  */
00113 
00114 #ifndef       _ANSIDECL_H
00115 #define _ANSIDECL_H  1
00116 
00117 /* Every source file includes this file,
00118    so they will all get the switch for lint.  */
00119 /* LINTLIBRARY */
00120 
00121 /* Using MACRO(x,y) in cpp #if conditionals does not work with some
00122    older preprocessors.  Thus we can't define something like this:
00123 
00124 #define HAVE_GCC_VERSION(MAJOR, MINOR) \
00125   (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
00126 
00127 and then test "#if HAVE_GCC_VERSION(2,7)".
00128 
00129 So instead we use the macro below and test it against specific values.  */
00130 
00131 /* This macro simplifies testing whether we are using gcc, and if it
00132    is of a particular minimum version. (Both major & minor numbers are
00133    significant.)  This macro will evaluate to 0 if we are not using
00134    gcc at all.  */
00135 #ifndef GCC_VERSION
00136 #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
00137 #endif /* GCC_VERSION */
00138 
00139 #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) || (defined(__alpha) && defined(__cplusplus))
00140 /* All known AIX compilers implement these things (but don't always
00141    define __STDC__).  The RISC/OS MIPS compiler defines these things
00142    in SVR4 mode, but does not define __STDC__.  */
00143 /* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
00144    C++ compilers, does not define __STDC__, though it acts as if this
00145    was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
00146 
00147 #define ANSI_PROTOTYPES     1
00148 #define PTR          void *
00149 #define PTRCONST     void *const
00150 #define LONG_DOUBLE  long double
00151 
00152 /* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in
00153    a #ifndef.  */
00154 #ifndef PARAMS
00155 #define PARAMS(ARGS)        ARGS
00156 #endif
00157 
00158 #define VPARAMS(ARGS)              ARGS
00159 #define VA_START(VA_LIST, VAR)     va_start(VA_LIST, VAR)
00160 
00161 /* variadic function helper macros */
00162 /* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's
00163    use without inhibiting further decls and without declaring an
00164    actual variable.  */
00165 #define VA_OPEN(AP, VAR)    { va_list AP; va_start(AP, VAR); { struct Qdmy
00166 #define VA_CLOSE(AP)        } va_end(AP); }
00167 #define VA_FIXEDARG(AP, T, N)      struct Qdmy
00168  
00169 #undef const
00170 #undef volatile
00171 #undef signed
00172 
00173 /* inline requires special treatment; it's in C99, and GCC >=2.7 supports
00174    it too, but it's not in C89.  */
00175 #undef inline
00176 #if __STDC_VERSION__ > 199901L
00177 /* it's a keyword */
00178 #else
00179 # if GCC_VERSION >= 2007
00180 #  define inline __inline__   /* __inline__ prevents -pedantic warnings */
00181 # else
00182 #  define inline  /* nothing */
00183 # endif
00184 #endif
00185 
00186 /* These are obsolete.  Do not use.  */
00187 #ifndef IN_GCC
00188 #define CONST        const
00189 #define VOLATILE     volatile
00190 #define SIGNED              signed
00191 
00192 #define PROTO(type, name, arglist) type name arglist
00193 #define EXFUN(name, proto)         name proto
00194 #define DEFUN(name, arglist, args) name(args)
00195 #define DEFUN_VOID(name)           name(void)
00196 #define AND          ,
00197 #define DOTS         , ...
00198 #define NOARGS              void
00199 #endif /* ! IN_GCC */
00200 
00201 #else  /* Not ANSI C.  */
00202 
00203 #undef  ANSI_PROTOTYPES
00204 #define PTR          char *
00205 #define PTRCONST     PTR
00206 #define LONG_DOUBLE  double
00207 
00208 #define PARAMS(args)        ()
00209 #define VPARAMS(args)              (va_alist) va_dcl
00210 #define VA_START(va_list, var)     va_start(va_list)
00211 
00212 #define VA_OPEN(AP, VAR)           { va_list AP; va_start(AP); { struct Qdmy
00213 #define VA_CLOSE(AP)               } va_end(AP); }
00214 #define VA_FIXEDARG(AP, TYPE, NAME)       TYPE NAME = va_arg(AP, TYPE)
00215 
00216 /* some systems define these in header files for non-ansi mode */
00217 #undef const
00218 #undef volatile
00219 #undef signed
00220 #undef inline
00221 #define const
00222 #define volatile
00223 #define signed
00224 #define inline
00225 
00226 #ifndef IN_GCC
00227 #define CONST
00228 #define VOLATILE
00229 #define SIGNED
00230 
00231 #define PROTO(type, name, arglist) type name ()
00232 #define EXFUN(name, proto)         name()
00233 #define DEFUN(name, arglist, args) name arglist args;
00234 #define DEFUN_VOID(name)           name()
00235 #define AND          ;
00236 #define DOTS
00237 #define NOARGS
00238 #endif /* ! IN_GCC */
00239 
00240 #endif /* ANSI C.  */
00241 
00242 /* Define macros for some gcc attributes.  This permits us to use the
00243    macros freely, and know that they will come into play for the
00244    version of gcc in which they are supported.  */
00245 
00246 #if (GCC_VERSION < 2007)
00247 # define __attribute__(x)
00248 #endif
00249 
00250 /* Attribute __malloc__ on functions was valid as of gcc 2.96. */
00251 #ifndef ATTRIBUTE_MALLOC
00252 # if (GCC_VERSION >= 2096)
00253 #  define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
00254 # else
00255 #  define ATTRIBUTE_MALLOC
00256 # endif /* GNUC >= 2.96 */
00257 #endif /* ATTRIBUTE_MALLOC */
00258 
00259 /* Attributes on labels were valid as of gcc 2.93. */
00260 #ifndef ATTRIBUTE_UNUSED_LABEL
00261 # if (!defined (__cplusplus) && GCC_VERSION >= 2093)
00262 #  define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
00263 # else
00264 #  define ATTRIBUTE_UNUSED_LABEL
00265 # endif /* !__cplusplus && GNUC >= 2.93 */
00266 #endif /* ATTRIBUTE_UNUSED_LABEL */
00267 
00268 #ifndef ATTRIBUTE_UNUSED
00269 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
00270 #endif /* ATTRIBUTE_UNUSED */
00271 
00272 /* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
00273    identifier name.  */
00274 #if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
00275 # define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
00276 #else /* !__cplusplus || GNUC >= 3.4 */
00277 # define ARG_UNUSED(NAME) NAME
00278 #endif /* !__cplusplus || GNUC >= 3.4 */
00279 
00280 #ifndef ATTRIBUTE_NORETURN
00281 #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
00282 #endif /* ATTRIBUTE_NORETURN */
00283 
00284 /* Attribute `nonnull' was valid as of gcc 3.3.  */
00285 #ifndef ATTRIBUTE_NONNULL
00286 # if (GCC_VERSION >= 3003)
00287 #  define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
00288 # else
00289 #  define ATTRIBUTE_NONNULL(m)
00290 # endif /* GNUC >= 3.3 */
00291 #endif /* ATTRIBUTE_NONNULL */
00292 
00293 /* Attribute `pure' was valid as of gcc 3.0.  */
00294 #ifndef ATTRIBUTE_PURE
00295 # if (GCC_VERSION >= 3000)
00296 #  define ATTRIBUTE_PURE __attribute__ ((__pure__))
00297 # else
00298 #  define ATTRIBUTE_PURE
00299 # endif /* GNUC >= 3.0 */
00300 #endif /* ATTRIBUTE_PURE */
00301 
00302 /* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
00303    This was the case for the `printf' format attribute by itself
00304    before GCC 3.3, but as of 3.3 we need to add the `nonnull'
00305    attribute to retain this behavior.  */
00306 #ifndef ATTRIBUTE_PRINTF
00307 #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
00308 #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
00309 #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
00310 #define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
00311 #define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
00312 #define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
00313 #endif /* ATTRIBUTE_PRINTF */
00314 
00315 /* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on
00316    a function pointer.  Format attributes were allowed on function
00317    pointers as of gcc 3.1.  */
00318 #ifndef ATTRIBUTE_FPTR_PRINTF
00319 # if (GCC_VERSION >= 3001)
00320 #  define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n)
00321 # else
00322 #  define ATTRIBUTE_FPTR_PRINTF(m, n)
00323 # endif /* GNUC >= 3.1 */
00324 # define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2)
00325 # define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3)
00326 # define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4)
00327 # define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5)
00328 # define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6)
00329 #endif /* ATTRIBUTE_FPTR_PRINTF */
00330 
00331 /* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL.  A
00332    NULL format specifier was allowed as of gcc 3.3.  */
00333 #ifndef ATTRIBUTE_NULL_PRINTF
00334 # if (GCC_VERSION >= 3003)
00335 #  define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
00336 # else
00337 #  define ATTRIBUTE_NULL_PRINTF(m, n)
00338 # endif /* GNUC >= 3.3 */
00339 # define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
00340 # define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
00341 # define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
00342 # define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
00343 # define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
00344 #endif /* ATTRIBUTE_NULL_PRINTF */
00345 
00346 /* Attribute `sentinel' was valid as of gcc 3.5.  */
00347 #ifndef ATTRIBUTE_SENTINEL
00348 # if (GCC_VERSION >= 3005)
00349 #  define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
00350 # else
00351 #  define ATTRIBUTE_SENTINEL
00352 # endif /* GNUC >= 3.5 */
00353 #endif /* ATTRIBUTE_SENTINEL */
00354 
00355 
00356 #ifndef ATTRIBUTE_ALIGNED_ALIGNOF
00357 # if (GCC_VERSION >= 3000)
00358 #  define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m))))
00359 # else
00360 #  define ATTRIBUTE_ALIGNED_ALIGNOF(m)
00361 # endif /* GNUC >= 3.0 */
00362 #endif /* ATTRIBUTE_ALIGNED_ALIGNOF */
00363 
00364 /* Useful for structures whose layout must much some binary specification
00365    regardless of the alignment and padding qualities of the compiler.  */
00366 #ifndef ATTRIBUTE_PACKED
00367 # define ATTRIBUTE_PACKED __attribute__ ((packed))
00368 #endif
00369 
00370 /* Attribute `hot' and `cold' was valid as of gcc 4.3.  */
00371 #ifndef ATTRIBUTE_COLD
00372 # if (GCC_VERSION >= 4003)
00373 #  define ATTRIBUTE_COLD __attribute__ ((__cold__))
00374 # else
00375 #  define ATTRIBUTE_COLD
00376 # endif /* GNUC >= 4.3 */
00377 #endif /* ATTRIBUTE_COLD */
00378 #ifndef ATTRIBUTE_HOT
00379 # if (GCC_VERSION >= 4003)
00380 #  define ATTRIBUTE_HOT __attribute__ ((__hot__))
00381 # else
00382 #  define ATTRIBUTE_HOT
00383 # endif /* GNUC >= 4.3 */
00384 #endif /* ATTRIBUTE_HOT */
00385 
00386 /* We use __extension__ in some places to suppress -pedantic warnings
00387    about GCC extensions.  This feature didn't work properly before
00388    gcc 2.8.  */
00389 #if GCC_VERSION < 2008
00390 #define __extension__
00391 #endif
00392 
00393 #endif /* ansidecl.h */