Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:29:36

0001 /* ANSI and traditional C compatability macros
0002    Copyright (C) 1991-2022 Free Software Foundation, Inc.
0003    This file is part of the GNU C Library.
0004 
0005 This program is free software; you can redistribute it and/or modify
0006 it under the terms of the GNU General Public License as published by
0007 the Free Software Foundation; either version 2 of the License, or
0008 (at your option) any later version.
0009 
0010 This program is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 GNU General Public License for more details.
0014 
0015 You should have received a copy of the GNU General Public License
0016 along with this program; if not, write to the Free Software
0017 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
0018 
0019 /* ANSI and traditional C compatibility macros
0020 
0021    ANSI C is assumed if __STDC__ is #defined.
0022 
0023    Macro        ANSI C definition   Traditional C definition
0024    -----        ---- - ----------   ----------- - ----------
0025    PTR          `void *'        `char *'
0026    const        not defined     `'
0027    volatile     not defined     `'
0028    signed       not defined     `'
0029 
0030    For ease of writing code which uses GCC extensions but needs to be
0031    portable to other compilers, we provide the GCC_VERSION macro that
0032    simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
0033    wrappers around __attribute__.  Also, __extension__ will be #defined
0034    to nothing if it doesn't work.  See below.  */
0035 
0036 #ifndef _ANSIDECL_H
0037 #define _ANSIDECL_H 1
0038 
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042 
0043 /* Every source file includes this file,
0044    so they will all get the switch for lint.  */
0045 /* LINTLIBRARY */
0046 
0047 /* Using MACRO(x,y) in cpp #if conditionals does not work with some
0048    older preprocessors.  Thus we can't define something like this:
0049 
0050 #define HAVE_GCC_VERSION(MAJOR, MINOR) \
0051   (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
0052 
0053 and then test "#if HAVE_GCC_VERSION(2,7)".
0054 
0055 So instead we use the macro below and test it against specific values.  */
0056 
0057 /* This macro simplifies testing whether we are using gcc, and if it
0058    is of a particular minimum version. (Both major & minor numbers are
0059    significant.)  This macro will evaluate to 0 if we are not using
0060    gcc at all.  */
0061 #ifndef GCC_VERSION
0062 #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
0063 #endif /* GCC_VERSION */
0064 
0065 #if defined (__STDC__) || defined(__cplusplus) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)
0066 /* All known AIX compilers implement these things (but don't always
0067    define __STDC__).  The RISC/OS MIPS compiler defines these things
0068    in SVR4 mode, but does not define __STDC__.  */
0069 /* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
0070    C++ compilers, does not define __STDC__, though it acts as if this
0071    was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
0072 
0073 #define PTR     void *
0074 
0075 #undef const
0076 #undef volatile
0077 #undef signed
0078 
0079 /* inline requires special treatment; it's in C99, and GCC >=2.7 supports
0080    it too, but it's not in C89.  */
0081 #undef inline
0082 #if __STDC_VERSION__ >= 199901L || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__))
0083 /* it's a keyword */
0084 #else
0085 # if GCC_VERSION >= 2007
0086 #  define inline __inline__   /* __inline__ prevents -pedantic warnings */
0087 # else
0088 #  define inline  /* nothing */
0089 # endif
0090 #endif
0091 
0092 #else   /* Not ANSI C.  */
0093 
0094 #define PTR     char *
0095 
0096 /* some systems define these in header files for non-ansi mode */
0097 #undef const
0098 #undef volatile
0099 #undef signed
0100 #undef inline
0101 #define const
0102 #define volatile
0103 #define signed
0104 #define inline
0105 
0106 #endif  /* ANSI C.  */
0107 
0108 /* Define macros for some gcc attributes.  This permits us to use the
0109    macros freely, and know that they will come into play for the
0110    version of gcc in which they are supported.  */
0111 
0112 #if (GCC_VERSION < 2007)
0113 # define __attribute__(x)
0114 #endif
0115 
0116 /* Attribute __malloc__ on functions was valid as of gcc 2.96. */
0117 #ifndef ATTRIBUTE_MALLOC
0118 # if (GCC_VERSION >= 2096)
0119 #  define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
0120 # else
0121 #  define ATTRIBUTE_MALLOC
0122 # endif /* GNUC >= 2.96 */
0123 #endif /* ATTRIBUTE_MALLOC */
0124 
0125 /* Attributes on labels were valid as of gcc 2.93 and g++ 4.5.  For
0126    g++ an attribute on a label must be followed by a semicolon.  */
0127 #ifndef ATTRIBUTE_UNUSED_LABEL
0128 # ifndef __cplusplus
0129 #  if GCC_VERSION >= 2093
0130 #   define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
0131 #  else
0132 #   define ATTRIBUTE_UNUSED_LABEL
0133 #  endif
0134 # else
0135 #  if GCC_VERSION >= 4005
0136 #   define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED ;
0137 #  else
0138 #   define ATTRIBUTE_UNUSED_LABEL
0139 #  endif
0140 # endif
0141 #endif
0142 
0143 /* Similarly to ARG_UNUSED below.  Prior to GCC 3.4, the C++ frontend
0144    couldn't parse attributes placed after the identifier name, and now
0145    the entire compiler is built with C++.  */
0146 #ifndef ATTRIBUTE_UNUSED
0147 #if GCC_VERSION >= 3004
0148 #  define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
0149 #else
0150 #define ATTRIBUTE_UNUSED
0151 #endif
0152 #endif /* ATTRIBUTE_UNUSED */
0153 
0154 /* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
0155    identifier name.  */
0156 #if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
0157 # define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
0158 #else /* !__cplusplus || GNUC >= 3.4 */
0159 # define ARG_UNUSED(NAME) NAME
0160 #endif /* !__cplusplus || GNUC >= 3.4 */
0161 
0162 #ifndef ATTRIBUTE_NORETURN
0163 #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
0164 #endif /* ATTRIBUTE_NORETURN */
0165 
0166 /* Attribute `nonnull' was valid as of gcc 3.3.  */
0167 #ifndef ATTRIBUTE_NONNULL
0168 # if (GCC_VERSION >= 3003)
0169 #  define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
0170 # else
0171 #  define ATTRIBUTE_NONNULL(m)
0172 # endif /* GNUC >= 3.3 */
0173 #endif /* ATTRIBUTE_NONNULL */
0174 
0175 /* Attribute `returns_nonnull' was valid as of gcc 4.9.  */
0176 #ifndef ATTRIBUTE_RETURNS_NONNULL
0177 # if (GCC_VERSION >= 4009)
0178 #  define ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
0179 # else
0180 #  define ATTRIBUTE_RETURNS_NONNULL
0181 # endif /* GNUC >= 4.9 */
0182 #endif /* ATTRIBUTE_RETURNS_NONNULL */
0183 
0184 /* Attribute `pure' was valid as of gcc 3.0.  */
0185 #ifndef ATTRIBUTE_PURE
0186 # if (GCC_VERSION >= 3000)
0187 #  define ATTRIBUTE_PURE __attribute__ ((__pure__))
0188 # else
0189 #  define ATTRIBUTE_PURE
0190 # endif /* GNUC >= 3.0 */
0191 #endif /* ATTRIBUTE_PURE */
0192 
0193 /* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
0194    This was the case for the `printf' format attribute by itself
0195    before GCC 3.3, but as of 3.3 we need to add the `nonnull'
0196    attribute to retain this behavior.  */
0197 #ifndef ATTRIBUTE_PRINTF
0198 #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
0199 #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
0200 #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
0201 #define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
0202 #define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
0203 #define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
0204 #endif /* ATTRIBUTE_PRINTF */
0205 
0206 /* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on
0207    a function pointer.  Format attributes were allowed on function
0208    pointers as of gcc 3.1.  */
0209 #ifndef ATTRIBUTE_FPTR_PRINTF
0210 # if (GCC_VERSION >= 3001)
0211 #  define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n)
0212 # else
0213 #  define ATTRIBUTE_FPTR_PRINTF(m, n)
0214 # endif /* GNUC >= 3.1 */
0215 # define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2)
0216 # define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3)
0217 # define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4)
0218 # define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5)
0219 # define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6)
0220 #endif /* ATTRIBUTE_FPTR_PRINTF */
0221 
0222 /* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL.  A
0223    NULL format specifier was allowed as of gcc 3.3.  */
0224 #ifndef ATTRIBUTE_NULL_PRINTF
0225 # if (GCC_VERSION >= 3003)
0226 #  define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
0227 # else
0228 #  define ATTRIBUTE_NULL_PRINTF(m, n)
0229 # endif /* GNUC >= 3.3 */
0230 # define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
0231 # define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
0232 # define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
0233 # define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
0234 # define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
0235 #endif /* ATTRIBUTE_NULL_PRINTF */
0236 
0237 /* Attribute `sentinel' was valid as of gcc 3.5.  */
0238 #ifndef ATTRIBUTE_SENTINEL
0239 # if (GCC_VERSION >= 3005)
0240 #  define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
0241 # else
0242 #  define ATTRIBUTE_SENTINEL
0243 # endif /* GNUC >= 3.5 */
0244 #endif /* ATTRIBUTE_SENTINEL */
0245 
0246 
0247 #ifndef ATTRIBUTE_ALIGNED_ALIGNOF
0248 # if (GCC_VERSION >= 3000)
0249 #  define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m))))
0250 # else
0251 #  define ATTRIBUTE_ALIGNED_ALIGNOF(m)
0252 # endif /* GNUC >= 3.0 */
0253 #endif /* ATTRIBUTE_ALIGNED_ALIGNOF */
0254 
0255 /* Useful for structures whose layout must match some binary specification
0256    regardless of the alignment and padding qualities of the compiler.  */
0257 #ifndef ATTRIBUTE_PACKED
0258 # define ATTRIBUTE_PACKED __attribute__ ((packed))
0259 #endif
0260 
0261 /* Attribute `hot' and `cold' was valid as of gcc 4.3.  */
0262 #ifndef ATTRIBUTE_COLD
0263 # if (GCC_VERSION >= 4003)
0264 #  define ATTRIBUTE_COLD __attribute__ ((__cold__))
0265 # else
0266 #  define ATTRIBUTE_COLD
0267 # endif /* GNUC >= 4.3 */
0268 #endif /* ATTRIBUTE_COLD */
0269 #ifndef ATTRIBUTE_HOT
0270 # if (GCC_VERSION >= 4003)
0271 #  define ATTRIBUTE_HOT __attribute__ ((__hot__))
0272 # else
0273 #  define ATTRIBUTE_HOT
0274 # endif /* GNUC >= 4.3 */
0275 #endif /* ATTRIBUTE_HOT */
0276 
0277 /* Attribute 'no_sanitize_undefined' was valid as of gcc 4.9.  */
0278 #ifndef ATTRIBUTE_NO_SANITIZE_UNDEFINED
0279 # if (GCC_VERSION >= 4009)
0280 #  define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__ ((no_sanitize_undefined))
0281 # else
0282 #  define ATTRIBUTE_NO_SANITIZE_UNDEFINED
0283 # endif /* GNUC >= 4.9 */
0284 #endif /* ATTRIBUTE_NO_SANITIZE_UNDEFINED */
0285 
0286 /* Attribute 'nonstring' was valid as of gcc 8.  */
0287 #ifndef ATTRIBUTE_NONSTRING
0288 # if GCC_VERSION >= 8000
0289 #  define ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
0290 # else
0291 #  define ATTRIBUTE_NONSTRING
0292 # endif
0293 #endif
0294 
0295 /* Attribute `alloc_size' was valid as of gcc 4.3.  */
0296 #ifndef ATTRIBUTE_RESULT_SIZE_1
0297 # if (GCC_VERSION >= 4003)
0298 #  define ATTRIBUTE_RESULT_SIZE_1 __attribute__ ((alloc_size (1)))
0299 # else
0300 #  define ATTRIBUTE_RESULT_SIZE_1
0301 #endif
0302 #endif
0303 
0304 #ifndef ATTRIBUTE_RESULT_SIZE_2
0305 # if (GCC_VERSION >= 4003)
0306 #  define ATTRIBUTE_RESULT_SIZE_2 __attribute__ ((alloc_size (2)))
0307 # else
0308 #  define ATTRIBUTE_RESULT_SIZE_2
0309 #endif
0310 #endif
0311 
0312 #ifndef ATTRIBUTE_RESULT_SIZE_1_2
0313 # if (GCC_VERSION >= 4003)
0314 #  define ATTRIBUTE_RESULT_SIZE_1_2 __attribute__ ((alloc_size (1, 2)))
0315 # else
0316 #  define ATTRIBUTE_RESULT_SIZE_1_2
0317 #endif
0318 #endif
0319 
0320 /* Attribute `warn_unused_result' was valid as of gcc 3.3.  */
0321 #ifndef ATTRIBUTE_WARN_UNUSED_RESULT
0322 # if GCC_VERSION >= 3003
0323 #  define ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
0324 # else
0325 #  define ATTRIBUTE_WARN_UNUSED_RESULT
0326 # endif
0327 #endif
0328 
0329 /* We use __extension__ in some places to suppress -pedantic warnings
0330    about GCC extensions.  This feature didn't work properly before
0331    gcc 2.8.  */
0332 #if GCC_VERSION < 2008
0333 #define __extension__
0334 #endif
0335 
0336 /* This is used to declare a const variable which should be visible
0337    outside of the current compilation unit.  Use it as
0338      EXPORTED_CONST int i = 1;
0339    This is because the semantics of const are different in C and C++.
0340    "extern const" is permitted in C but it looks strange, and gcc
0341    warns about it when -Wc++-compat is not used.  */
0342 #ifdef __cplusplus
0343 #define EXPORTED_CONST extern const
0344 #else
0345 #define EXPORTED_CONST const
0346 #endif
0347 
0348 /* Be conservative and only use enum bitfields with C++ or GCC.
0349    FIXME: provide a complete autoconf test for buggy enum bitfields.  */
0350 
0351 #ifdef __cplusplus
0352 #define ENUM_BITFIELD(TYPE) enum TYPE
0353 #elif (GCC_VERSION > 2000)
0354 #define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
0355 #else
0356 #define ENUM_BITFIELD(TYPE) unsigned int
0357 #endif
0358 
0359 #if __cpp_constexpr >= 200704
0360 #define CONSTEXPR constexpr
0361 #else
0362 #define CONSTEXPR
0363 #endif
0364 
0365 /* C++11 adds the ability to add "override" after an implementation of a
0366    virtual function in a subclass, to:
0367      (A) document that this is an override of a virtual function
0368      (B) allow the compiler to issue a warning if it isn't (e.g. a mismatch
0369          of the type signature).
0370 
0371    Similarly, it allows us to add a "final" to indicate that no subclass
0372    may subsequently override the vfunc.
0373 
0374    Provide OVERRIDE and FINAL as macros, allowing us to get these benefits
0375    when compiling with C++11 support, but without requiring C++11.
0376 
0377    For gcc, use "-std=c++11" to enable C++11 support; gcc 6 onwards enables
0378    this by default (actually GNU++14).  */
0379 
0380 #if defined __cplusplus
0381 # if __cplusplus >= 201103
0382    /* C++11 claims to be available: use it.  Final/override were only
0383       implemented in 4.7, though.  */
0384 #  if GCC_VERSION < 4007
0385 #   define OVERRIDE
0386 #   define FINAL
0387 #  else
0388 #   define OVERRIDE override
0389 #   define FINAL final
0390 #  endif
0391 # elif GCC_VERSION >= 4007
0392    /* G++ 4.7 supports __final in C++98.  */
0393 #  define OVERRIDE
0394 #  define FINAL __final
0395 # else
0396    /* No C++11 support; leave the macros empty.  */
0397 #  define OVERRIDE
0398 #  define FINAL
0399 # endif
0400 #else
0401   /* No C++11 support; leave the macros empty.  */
0402 # define OVERRIDE
0403 # define FINAL
0404 #endif
0405 
0406 /* A macro to disable the copy constructor and assignment operator.
0407    When building with C++11 and above, the methods are explicitly
0408    deleted, causing a compile-time error if something tries to copy.
0409    For C++03, this just declares the methods, causing a link-time
0410    error if the methods end up called (assuming you don't
0411    define them).  For C++03, for best results, place the macro
0412    under the private: access specifier, like this,
0413 
0414    class name_lookup
0415    {
0416      private:
0417        DISABLE_COPY_AND_ASSIGN (name_lookup);
0418    };
0419 
0420    so that most attempts at copy are caught at compile-time.  */
0421 
0422 #if __cplusplus >= 201103
0423 #define DISABLE_COPY_AND_ASSIGN(TYPE)       \
0424   TYPE (const TYPE&) = delete;          \
0425   void operator= (const TYPE &) = delete
0426   #else
0427 #define DISABLE_COPY_AND_ASSIGN(TYPE)       \
0428   TYPE (const TYPE&);               \
0429   void operator= (const TYPE &)
0430 #endif /* __cplusplus >= 201103 */
0431 
0432 #ifdef __cplusplus
0433 }
0434 #endif
0435 
0436 #endif  /* ansidecl.h   */