Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* ANSI and traditional C compatability macros |
52d6785f | 2 | Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, |
281e9aa6 | 3 | 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2013 |
4f1d9bd8 | 4 | Free Software Foundation, Inc. |
252b5132 RH |
5 | This file is part of the GNU C Library. |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
e172dbf8 | 19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 RH |
20 | |
21 | /* ANSI and traditional C compatibility macros | |
22 | ||
23 | ANSI C is assumed if __STDC__ is #defined. | |
24 | ||
562c4c36 DD |
25 | Macro ANSI C definition Traditional C definition |
26 | ----- ---- - ---------- ----------- - ---------- | |
562c4c36 | 27 | PTR `void *' `char *' |
562c4c36 DD |
28 | const not defined `' |
29 | volatile not defined `' | |
30 | signed not defined `' | |
562c4c36 DD |
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 | |
281e9aa6 | 36 | to nothing if it doesn't work. See below. */ |
252b5132 RH |
37 | |
38 | #ifndef _ANSIDECL_H | |
562c4c36 | 39 | #define _ANSIDECL_H 1 |
252b5132 | 40 | |
52d6785f DD |
41 | #ifdef __cplusplus |
42 | extern "C" { | |
43 | #endif | |
44 | ||
252b5132 RH |
45 | /* Every source file includes this file, |
46 | so they will all get the switch for lint. */ | |
47 | /* LINTLIBRARY */ | |
48 | ||
562c4c36 DD |
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 | ||
55 | and then test "#if HAVE_GCC_VERSION(2,7)". | |
56 | ||
57 | So 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 */ | |
252b5132 | 66 | |
52d6785f | 67 | #if defined (__STDC__) || defined(__cplusplus) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) |
252b5132 RH |
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__. */ | |
995a8435 DD |
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) */ | |
252b5132 | 74 | |
562c4c36 | 75 | #define PTR void * |
562c4c36 | 76 | |
562c4c36 DD |
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 | |
43e85a8f | 84 | #if __STDC_VERSION__ >= 199901L || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__)) |
562c4c36 DD |
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 | |
252b5132 | 93 | |
252b5132 RH |
94 | #else /* Not ANSI C. */ |
95 | ||
562c4c36 | 96 | #define PTR char * |
562c4c36 DD |
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 | |
252b5132 | 107 | |
252b5132 RH |
108 | #endif /* ANSI C. */ |
109 | ||
893e9593 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 | ||
4597ba0f | 114 | #if (GCC_VERSION < 2007) |
893e9593 ILT |
115 | # define __attribute__(x) |
116 | #endif | |
117 | ||
4597ba0f ILT |
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__)) | |
893e9593 | 122 | # else |
4597ba0f ILT |
123 | # define ATTRIBUTE_MALLOC |
124 | # endif /* GNUC >= 2.96 */ | |
125 | #endif /* ATTRIBUTE_MALLOC */ | |
126 | ||
671f4ed1 DD |
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. */ | |
4597ba0f | 129 | #ifndef ATTRIBUTE_UNUSED_LABEL |
671f4ed1 DD |
130 | # ifndef __cplusplus |
131 | # if GCC_VERSION >= 2093 | |
132 | # define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED | |
133 | # else | |
134 | # define ATTRIBUTE_UNUSED_LABEL | |
135 | # endif | |
4597ba0f | 136 | # else |
671f4ed1 DD |
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 | |
893e9593 | 144 | |
ddd27bde DD |
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++. */ | |
893e9593 | 148 | #ifndef ATTRIBUTE_UNUSED |
ddd27bde DD |
149 | #if GCC_VERSION >= 3004 |
150 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | |
151 | #else | |
152 | #define ATTRIBUTE_UNUSED | |
153 | #endif | |
893e9593 ILT |
154 | #endif /* ATTRIBUTE_UNUSED */ |
155 | ||
d5b4094f DD |
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 | ||
893e9593 ILT |
164 | #ifndef ATTRIBUTE_NORETURN |
165 | #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | |
166 | #endif /* ATTRIBUTE_NORETURN */ | |
167 | ||
bf8db3d4 DD |
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 | ||
689a1abf | 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 | ||
a35b6b04 DD |
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 | ||
bf8db3d4 DD |
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. */ | |
893e9593 | 199 | #ifndef ATTRIBUTE_PRINTF |
bf8db3d4 | 200 | #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m) |
893e9593 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 | ||
e9472921 DD |
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 | ||
bf8db3d4 DD |
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 | ||
a5ecc6a5 DD |
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 | ||
6ba85b8c DD |
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 | ||
ce493bd9 | 257 | /* Useful for structures whose layout must much some binary specification |
4fd454c8 NC |
258 | regardless of the alignment and padding qualities of the compiler. */ |
259 | #ifndef ATTRIBUTE_PACKED | |
260 | # define ATTRIBUTE_PACKED __attribute__ ((packed)) | |
261 | #endif | |
262 | ||
e04d7611 DD |
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 | ||
f1d95f4b L |
279 | /* We use __extension__ in some places to suppress -pedantic warnings |
280 | about GCC extensions. This feature didn't work properly before | |
281 | gcc 2.8. */ | |
282 | #if GCC_VERSION < 2008 | |
283 | #define __extension__ | |
284 | #endif | |
285 | ||
8466c6d4 DD |
286 | /* This is used to declare a const variable which should be visible |
287 | outside of the current compilation unit. Use it as | |
288 | EXPORTED_CONST int i = 1; | |
289 | This is because the semantics of const are different in C and C++. | |
290 | "extern const" is permitted in C but it looks strange, and gcc | |
291 | warns about it when -Wc++-compat is not used. */ | |
292 | #ifdef __cplusplus | |
293 | #define EXPORTED_CONST extern const | |
294 | #else | |
295 | #define EXPORTED_CONST const | |
296 | #endif | |
297 | ||
006d5c88 | 298 | /* Be conservative and only use enum bitfields with C++ or GCC. |
1ae0d051 JK |
299 | FIXME: provide a complete autoconf test for buggy enum bitfields. */ |
300 | ||
006d5c88 DD |
301 | #ifdef __cplusplus |
302 | #define ENUM_BITFIELD(TYPE) enum TYPE | |
303 | #elif (GCC_VERSION > 2000) | |
1ae0d051 JK |
304 | #define ENUM_BITFIELD(TYPE) __extension__ enum TYPE |
305 | #else | |
306 | #define ENUM_BITFIELD(TYPE) unsigned int | |
307 | #endif | |
308 | ||
52d6785f DD |
309 | #ifdef __cplusplus |
310 | } | |
311 | #endif | |
312 | ||
252b5132 | 313 | #endif /* ansidecl.h */ |