]> git.ipfire.org Git - thirdparty/gcc.git/blame - include/ansidecl.h
contrib.texi (Contributors): Update entry for Danny Smith.
[thirdparty/gcc.git] / include / ansidecl.h
CommitLineData
6599da04 1/* ANSI and traditional C compatability macros
75afccba 2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
d2d21de9 3 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2013
01f537ab 4 Free Software Foundation, Inc.
6599da04
JM
5 This file is part of the GNU C Library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
d6d47ea0 19Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
6599da04
JM
20
21/* ANSI and traditional C compatibility macros
22
23 ANSI C is assumed if __STDC__ is #defined.
24
b649398a
ZW
25 Macro ANSI C definition Traditional C definition
26 ----- ---- - ---------- ----------- - ----------
b649398a 27 PTR `void *' `char *'
b649398a
ZW
28 const not defined `'
29 volatile not defined `'
30 signed not defined `'
b649398a
ZW
31
32 For ease of writing code which uses GCC extensions but needs to be
33 portable to other compilers, we provide the GCC_VERSION macro that
34 simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
35 wrappers around __attribute__. Also, __extension__ will be #defined
d2d21de9 36 to nothing if it doesn't work. See below. */
6599da04
JM
37
38#ifndef _ANSIDECL_H
b649398a 39#define _ANSIDECL_H 1
6599da04 40
75afccba
ILT
41#ifdef __cplusplus
42extern "C" {
43#endif
44
6599da04
JM
45/* Every source file includes this file,
46 so they will all get the switch for lint. */
47/* LINTLIBRARY */
48
b649398a
ZW
49/* Using MACRO(x,y) in cpp #if conditionals does not work with some
50 older preprocessors. Thus we can't define something like this:
51
52#define HAVE_GCC_VERSION(MAJOR, MINOR) \
53 (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
54
55and then test "#if HAVE_GCC_VERSION(2,7)".
56
57So instead we use the macro below and test it against specific values. */
58
59/* This macro simplifies testing whether we are using gcc, and if it
60 is of a particular minimum version. (Both major & minor numbers are
61 significant.) This macro will evaluate to 0 if we are not using
62 gcc at all. */
63#ifndef GCC_VERSION
64#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
65#endif /* GCC_VERSION */
6599da04 66
75afccba 67#if defined (__STDC__) || defined(__cplusplus) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)
6599da04
JM
68/* All known AIX compilers implement these things (but don't always
69 define __STDC__). The RISC/OS MIPS compiler defines these things
70 in SVR4 mode, but does not define __STDC__. */
e4aaa2f8
NT
71/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
72 C++ compilers, does not define __STDC__, though it acts as if this
73 was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
6599da04 74
b649398a 75#define PTR void *
b649398a 76
b649398a
ZW
77#undef const
78#undef volatile
79#undef signed
80
81/* inline requires special treatment; it's in C99, and GCC >=2.7 supports
82 it too, but it's not in C89. */
83#undef inline
6a4d4e8a 84#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__))
b649398a
ZW
85/* it's a keyword */
86#else
87# if GCC_VERSION >= 2007
88# define inline __inline__ /* __inline__ prevents -pedantic warnings */
89# else
90# define inline /* nothing */
91# endif
92#endif
6599da04 93
6599da04
JM
94#else /* Not ANSI C. */
95
b649398a 96#define PTR char *
b649398a
ZW
97
98/* some systems define these in header files for non-ansi mode */
99#undef const
100#undef volatile
101#undef signed
102#undef inline
103#define const
104#define volatile
105#define signed
106#define inline
6599da04 107
6599da04
JM
108#endif /* ANSI C. */
109
e428b1a8
ILT
110/* Define macros for some gcc attributes. This permits us to use the
111 macros freely, and know that they will come into play for the
112 version of gcc in which they are supported. */
113
6c9821b7 114#if (GCC_VERSION < 2007)
e428b1a8
ILT
115# define __attribute__(x)
116#endif
117
d9465687
KG
118/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
119#ifndef ATTRIBUTE_MALLOC
120# if (GCC_VERSION >= 2096)
121# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
122# else
123# define ATTRIBUTE_MALLOC
124# endif /* GNUC >= 2.96 */
125#endif /* ATTRIBUTE_MALLOC */
126
780ca5bf
ILT
127/* Attributes on labels were valid as of gcc 2.93 and g++ 4.5. For
128 g++ an attribute on a label must be followed by a semicolon. */
e428b1a8 129#ifndef ATTRIBUTE_UNUSED_LABEL
780ca5bf
ILT
130# ifndef __cplusplus
131# if GCC_VERSION >= 2093
132# define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
133# else
134# define ATTRIBUTE_UNUSED_LABEL
135# endif
6c9821b7 136# else
780ca5bf
ILT
137# if GCC_VERSION >= 4005
138# define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED ;
139# else
140# define ATTRIBUTE_UNUSED_LABEL
141# endif
142# endif
143#endif
e428b1a8 144
9654e9c2
AH
145/* Similarly to ARG_UNUSED below. Prior to GCC 3.4, the C++ frontend
146 couldn't parse attributes placed after the identifier name, and now
147 the entire compiler is built with C++. */
e428b1a8 148#ifndef ATTRIBUTE_UNUSED
9654e9c2
AH
149#if GCC_VERSION >= 3004
150# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
151#else
152#define ATTRIBUTE_UNUSED
153#endif
e428b1a8
ILT
154#endif /* ATTRIBUTE_UNUSED */
155
5673cd61
BI
156/* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
157 identifier name. */
158#if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
159# define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
160#else /* !__cplusplus || GNUC >= 3.4 */
161# define ARG_UNUSED(NAME) NAME
162#endif /* !__cplusplus || GNUC >= 3.4 */
163
e428b1a8
ILT
164#ifndef ATTRIBUTE_NORETURN
165#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
166#endif /* ATTRIBUTE_NORETURN */
167
d41c4351
KG
168/* Attribute `nonnull' was valid as of gcc 3.3. */
169#ifndef ATTRIBUTE_NONNULL
170# if (GCC_VERSION >= 3003)
171# define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
172# else
173# define ATTRIBUTE_NONNULL(m)
174# endif /* GNUC >= 3.3 */
175#endif /* ATTRIBUTE_NONNULL */
176
eda14d6a
MG
177/* Attribute `returns_nonnull' was valid as of gcc 4.9. */
178#ifndef ATTRIBUTE_RETURNS_NONNULL
179# if (GCC_VERSION >= 4009)
180# define ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
181# else
182# define ATTRIBUTE_RETURNS_NONNULL
183# endif /* GNUC >= 4.9 */
184#endif /* ATTRIBUTE_RETURNS_NONNULL */
185
4b997cc8
PB
186/* Attribute `pure' was valid as of gcc 3.0. */
187#ifndef ATTRIBUTE_PURE
188# if (GCC_VERSION >= 3000)
189# define ATTRIBUTE_PURE __attribute__ ((__pure__))
190# else
191# define ATTRIBUTE_PURE
192# endif /* GNUC >= 3.0 */
193#endif /* ATTRIBUTE_PURE */
194
d41c4351
KG
195/* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
196 This was the case for the `printf' format attribute by itself
197 before GCC 3.3, but as of 3.3 we need to add the `nonnull'
198 attribute to retain this behavior. */
e428b1a8 199#ifndef ATTRIBUTE_PRINTF
d41c4351 200#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
e428b1a8
ILT
201#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
202#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
203#define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
204#define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
205#define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
206#endif /* ATTRIBUTE_PRINTF */
207
b6e0f0b0
KG
208/* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on
209 a function pointer. Format attributes were allowed on function
210 pointers as of gcc 3.1. */
211#ifndef ATTRIBUTE_FPTR_PRINTF
212# if (GCC_VERSION >= 3001)
213# define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n)
214# else
215# define ATTRIBUTE_FPTR_PRINTF(m, n)
216# endif /* GNUC >= 3.1 */
217# define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2)
218# define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3)
219# define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4)
220# define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5)
221# define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6)
222#endif /* ATTRIBUTE_FPTR_PRINTF */
223
d41c4351
KG
224/* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A
225 NULL format specifier was allowed as of gcc 3.3. */
226#ifndef ATTRIBUTE_NULL_PRINTF
227# if (GCC_VERSION >= 3003)
228# define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
229# else
230# define ATTRIBUTE_NULL_PRINTF(m, n)
231# endif /* GNUC >= 3.3 */
232# define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
233# define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
234# define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
235# define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
236# define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
237#endif /* ATTRIBUTE_NULL_PRINTF */
238
3d091dac
KG
239/* Attribute `sentinel' was valid as of gcc 3.5. */
240#ifndef ATTRIBUTE_SENTINEL
241# if (GCC_VERSION >= 3005)
242# define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
243# else
244# define ATTRIBUTE_SENTINEL
245# endif /* GNUC >= 3.5 */
246#endif /* ATTRIBUTE_SENTINEL */
247
3fe725de
SE
248
249#ifndef ATTRIBUTE_ALIGNED_ALIGNOF
250# if (GCC_VERSION >= 3000)
251# define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m))))
252# else
253# define ATTRIBUTE_ALIGNED_ALIGNOF(m)
254# endif /* GNUC >= 3.0 */
255#endif /* ATTRIBUTE_ALIGNED_ALIGNOF */
256
0307c64e
NC
257/* Useful for structures whose layout must much some binary specification
258 regardless of the alignment and padding qualities of the compiler. */
259#ifndef ATTRIBUTE_PACKED
260# define ATTRIBUTE_PACKED __attribute__ ((packed))
261#endif
262
52bf96d2
JH
263/* Attribute `hot' and `cold' was valid as of gcc 4.3. */
264#ifndef ATTRIBUTE_COLD
265# if (GCC_VERSION >= 4003)
266# define ATTRIBUTE_COLD __attribute__ ((__cold__))
267# else
268# define ATTRIBUTE_COLD
269# endif /* GNUC >= 4.3 */
270#endif /* ATTRIBUTE_COLD */
271#ifndef ATTRIBUTE_HOT
272# if (GCC_VERSION >= 4003)
273# define ATTRIBUTE_HOT __attribute__ ((__hot__))
274# else
275# define ATTRIBUTE_HOT
276# endif /* GNUC >= 4.3 */
277#endif /* ATTRIBUTE_HOT */
278
44d95244
MT
279/* Attribute 'no_sanitize_undefined' was valid as of gcc 4.9. */
280#ifndef ATTRIBUTE_NO_SANITIZE_UNDEFINED
281# if (GCC_VERSION >= 4009)
282# define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__ ((no_sanitize_undefined))
283# else
284# define ATTRIBUTE_NO_SANITIZE_UNDEFINED
285# endif /* GNUC >= 4.9 */
286#endif /* ATTRIBUTE_NO_SANITIZE_UNDEFINED */
287
8784fdcd
ZW
288/* We use __extension__ in some places to suppress -pedantic warnings
289 about GCC extensions. This feature didn't work properly before
290 gcc 2.8. */
291#if GCC_VERSION < 2008
292#define __extension__
293#endif
294
6bc7bc14
ILT
295/* This is used to declare a const variable which should be visible
296 outside of the current compilation unit. Use it as
297 EXPORTED_CONST int i = 1;
298 This is because the semantics of const are different in C and C++.
299 "extern const" is permitted in C but it looks strange, and gcc
300 warns about it when -Wc++-compat is not used. */
301#ifdef __cplusplus
302#define EXPORTED_CONST extern const
303#else
304#define EXPORTED_CONST const
305#endif
306
40c4cbcd 307/* Be conservative and only use enum bitfields with C++ or GCC.
e5b0dad8
JK
308 FIXME: provide a complete autoconf test for buggy enum bitfields. */
309
40c4cbcd
DD
310#ifdef __cplusplus
311#define ENUM_BITFIELD(TYPE) enum TYPE
312#elif (GCC_VERSION > 2000)
e5b0dad8
JK
313#define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
314#else
315#define ENUM_BITFIELD(TYPE) unsigned int
316#endif
317
75afccba
ILT
318#ifdef __cplusplus
319}
320#endif
321
6599da04 322#endif /* ansidecl.h */