]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - include/ansidecl.h
[PATCH] fix windmc typedef bug
[thirdparty/binutils-gdb.git] / include / ansidecl.h
CommitLineData
252b5132 1/* ANSI and traditional C compatability macros
b3adc24a 2 Copyright (C) 1991-2020 Free Software Foundation, Inc.
252b5132
RH
3 This file is part of the GNU C Library.
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
e172dbf8 17Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
252b5132
RH
18
19/* ANSI and traditional C compatibility macros
20
21 ANSI C is assumed if __STDC__ is #defined.
22
562c4c36
DD
23 Macro ANSI C definition Traditional C definition
24 ----- ---- - ---------- ----------- - ----------
562c4c36 25 PTR `void *' `char *'
562c4c36
DD
26 const not defined `'
27 volatile not defined `'
28 signed not defined `'
562c4c36
DD
29
30 For ease of writing code which uses GCC extensions but needs to be
31 portable to other compilers, we provide the GCC_VERSION macro that
32 simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
33 wrappers around __attribute__. Also, __extension__ will be #defined
281e9aa6 34 to nothing if it doesn't work. See below. */
252b5132
RH
35
36#ifndef _ANSIDECL_H
562c4c36 37#define _ANSIDECL_H 1
252b5132 38
52d6785f
DD
39#ifdef __cplusplus
40extern "C" {
41#endif
42
252b5132
RH
43/* Every source file includes this file,
44 so they will all get the switch for lint. */
45/* LINTLIBRARY */
46
562c4c36
DD
47/* Using MACRO(x,y) in cpp #if conditionals does not work with some
48 older preprocessors. Thus we can't define something like this:
49
50#define HAVE_GCC_VERSION(MAJOR, MINOR) \
51 (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
52
53and then test "#if HAVE_GCC_VERSION(2,7)".
54
55So instead we use the macro below and test it against specific values. */
56
57/* This macro simplifies testing whether we are using gcc, and if it
58 is of a particular minimum version. (Both major & minor numbers are
59 significant.) This macro will evaluate to 0 if we are not using
60 gcc at all. */
61#ifndef GCC_VERSION
62#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
63#endif /* GCC_VERSION */
252b5132 64
52d6785f 65#if defined (__STDC__) || defined(__cplusplus) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)
252b5132
RH
66/* All known AIX compilers implement these things (but don't always
67 define __STDC__). The RISC/OS MIPS compiler defines these things
68 in SVR4 mode, but does not define __STDC__. */
995a8435
DD
69/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
70 C++ compilers, does not define __STDC__, though it acts as if this
71 was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
252b5132 72
562c4c36 73#define PTR void *
562c4c36 74
562c4c36
DD
75#undef const
76#undef volatile
77#undef signed
78
79/* inline requires special treatment; it's in C99, and GCC >=2.7 supports
80 it too, but it's not in C89. */
81#undef inline
43e85a8f 82#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__))
562c4c36
DD
83/* it's a keyword */
84#else
85# if GCC_VERSION >= 2007
86# define inline __inline__ /* __inline__ prevents -pedantic warnings */
87# else
88# define inline /* nothing */
89# endif
90#endif
252b5132 91
252b5132
RH
92#else /* Not ANSI C. */
93
562c4c36 94#define PTR char *
562c4c36
DD
95
96/* some systems define these in header files for non-ansi mode */
97#undef const
98#undef volatile
99#undef signed
100#undef inline
101#define const
102#define volatile
103#define signed
104#define inline
252b5132 105
252b5132
RH
106#endif /* ANSI C. */
107
893e9593
ILT
108/* Define macros for some gcc attributes. This permits us to use the
109 macros freely, and know that they will come into play for the
110 version of gcc in which they are supported. */
111
4597ba0f 112#if (GCC_VERSION < 2007)
893e9593
ILT
113# define __attribute__(x)
114#endif
115
4597ba0f
ILT
116/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
117#ifndef ATTRIBUTE_MALLOC
118# if (GCC_VERSION >= 2096)
119# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
893e9593 120# else
4597ba0f
ILT
121# define ATTRIBUTE_MALLOC
122# endif /* GNUC >= 2.96 */
123#endif /* ATTRIBUTE_MALLOC */
124
671f4ed1
DD
125/* Attributes on labels were valid as of gcc 2.93 and g++ 4.5. For
126 g++ an attribute on a label must be followed by a semicolon. */
4597ba0f 127#ifndef ATTRIBUTE_UNUSED_LABEL
671f4ed1
DD
128# ifndef __cplusplus
129# if GCC_VERSION >= 2093
130# define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
131# else
132# define ATTRIBUTE_UNUSED_LABEL
133# endif
4597ba0f 134# else
671f4ed1
DD
135# if GCC_VERSION >= 4005
136# define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED ;
137# else
138# define ATTRIBUTE_UNUSED_LABEL
139# endif
140# endif
141#endif
893e9593 142
ddd27bde
DD
143/* Similarly to ARG_UNUSED below. Prior to GCC 3.4, the C++ frontend
144 couldn't parse attributes placed after the identifier name, and now
145 the entire compiler is built with C++. */
893e9593 146#ifndef ATTRIBUTE_UNUSED
ddd27bde
DD
147#if GCC_VERSION >= 3004
148# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
149#else
150#define ATTRIBUTE_UNUSED
151#endif
893e9593
ILT
152#endif /* ATTRIBUTE_UNUSED */
153
d5b4094f
DD
154/* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
155 identifier name. */
156#if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
157# define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
158#else /* !__cplusplus || GNUC >= 3.4 */
159# define ARG_UNUSED(NAME) NAME
160#endif /* !__cplusplus || GNUC >= 3.4 */
161
893e9593
ILT
162#ifndef ATTRIBUTE_NORETURN
163#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
164#endif /* ATTRIBUTE_NORETURN */
165
bf8db3d4
DD
166/* Attribute `nonnull' was valid as of gcc 3.3. */
167#ifndef ATTRIBUTE_NONNULL
168# if (GCC_VERSION >= 3003)
169# define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
170# else
171# define ATTRIBUTE_NONNULL(m)
172# endif /* GNUC >= 3.3 */
173#endif /* ATTRIBUTE_NONNULL */
174
689a1abf 175/* Attribute `returns_nonnull' was valid as of gcc 4.9. */
176#ifndef ATTRIBUTE_RETURNS_NONNULL
177# if (GCC_VERSION >= 4009)
178# define ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
179# else
180# define ATTRIBUTE_RETURNS_NONNULL
181# endif /* GNUC >= 4.9 */
182#endif /* ATTRIBUTE_RETURNS_NONNULL */
183
a35b6b04
DD
184/* Attribute `pure' was valid as of gcc 3.0. */
185#ifndef ATTRIBUTE_PURE
186# if (GCC_VERSION >= 3000)
187# define ATTRIBUTE_PURE __attribute__ ((__pure__))
188# else
189# define ATTRIBUTE_PURE
190# endif /* GNUC >= 3.0 */
191#endif /* ATTRIBUTE_PURE */
192
bf8db3d4
DD
193/* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
194 This was the case for the `printf' format attribute by itself
195 before GCC 3.3, but as of 3.3 we need to add the `nonnull'
196 attribute to retain this behavior. */
893e9593 197#ifndef ATTRIBUTE_PRINTF
bf8db3d4 198#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
893e9593
ILT
199#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
200#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
201#define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
202#define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
203#define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
204#endif /* ATTRIBUTE_PRINTF */
205
e9472921
DD
206/* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on
207 a function pointer. Format attributes were allowed on function
208 pointers as of gcc 3.1. */
209#ifndef ATTRIBUTE_FPTR_PRINTF
210# if (GCC_VERSION >= 3001)
211# define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n)
212# else
213# define ATTRIBUTE_FPTR_PRINTF(m, n)
214# endif /* GNUC >= 3.1 */
215# define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2)
216# define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3)
217# define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4)
218# define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5)
219# define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6)
220#endif /* ATTRIBUTE_FPTR_PRINTF */
221
bf8db3d4
DD
222/* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A
223 NULL format specifier was allowed as of gcc 3.3. */
224#ifndef ATTRIBUTE_NULL_PRINTF
225# if (GCC_VERSION >= 3003)
226# define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
227# else
228# define ATTRIBUTE_NULL_PRINTF(m, n)
229# endif /* GNUC >= 3.3 */
230# define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
231# define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
232# define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
233# define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
234# define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
235#endif /* ATTRIBUTE_NULL_PRINTF */
236
a5ecc6a5
DD
237/* Attribute `sentinel' was valid as of gcc 3.5. */
238#ifndef ATTRIBUTE_SENTINEL
239# if (GCC_VERSION >= 3005)
240# define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
241# else
242# define ATTRIBUTE_SENTINEL
243# endif /* GNUC >= 3.5 */
244#endif /* ATTRIBUTE_SENTINEL */
245
6ba85b8c
DD
246
247#ifndef ATTRIBUTE_ALIGNED_ALIGNOF
248# if (GCC_VERSION >= 3000)
249# define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m))))
250# else
251# define ATTRIBUTE_ALIGNED_ALIGNOF(m)
252# endif /* GNUC >= 3.0 */
253#endif /* ATTRIBUTE_ALIGNED_ALIGNOF */
254
26a67918 255/* Useful for structures whose layout must match some binary specification
4fd454c8
NC
256 regardless of the alignment and padding qualities of the compiler. */
257#ifndef ATTRIBUTE_PACKED
258# define ATTRIBUTE_PACKED __attribute__ ((packed))
259#endif
260
e04d7611
DD
261/* Attribute `hot' and `cold' was valid as of gcc 4.3. */
262#ifndef ATTRIBUTE_COLD
263# if (GCC_VERSION >= 4003)
264# define ATTRIBUTE_COLD __attribute__ ((__cold__))
265# else
266# define ATTRIBUTE_COLD
267# endif /* GNUC >= 4.3 */
268#endif /* ATTRIBUTE_COLD */
269#ifndef ATTRIBUTE_HOT
270# if (GCC_VERSION >= 4003)
271# define ATTRIBUTE_HOT __attribute__ ((__hot__))
272# else
273# define ATTRIBUTE_HOT
274# endif /* GNUC >= 4.3 */
275#endif /* ATTRIBUTE_HOT */
276
4d6404f0
L
277/* Attribute 'no_sanitize_undefined' was valid as of gcc 4.9. */
278#ifndef ATTRIBUTE_NO_SANITIZE_UNDEFINED
279# if (GCC_VERSION >= 4009)
280# define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__ ((no_sanitize_undefined))
281# else
282# define ATTRIBUTE_NO_SANITIZE_UNDEFINED
283# endif /* GNUC >= 4.9 */
284#endif /* ATTRIBUTE_NO_SANITIZE_UNDEFINED */
285
602f1657
AM
286/* Attribute 'nonstring' was valid as of gcc 8. */
287#ifndef ATTRIBUTE_NONSTRING
288# if GCC_VERSION >= 8000
289# define ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
290# else
291# define ATTRIBUTE_NONSTRING
292# endif
293#endif
294
533da483
NC
295/* Attribute `alloc_size' was valid as of gcc 4.3. */
296#ifndef ATTRIBUTE_RESULT_SIZE_1
297# if (GCC_VERSION >= 4003)
298# define ATTRIBUTE_RESULT_SIZE_1 __attribute__ ((alloc_size (1)))
299# else
300# define ATTRIBUTE_RESULT_SIZE_1
301#endif
302#endif
303
304#ifndef ATTRIBUTE_RESULT_SIZE_2
305# if (GCC_VERSION >= 4003)
306# define ATTRIBUTE_RESULT_SIZE_2 __attribute__ ((alloc_size (2)))
307# else
308# define ATTRIBUTE_RESULT_SIZE_2
309#endif
310#endif
311
312#ifndef ATTRIBUTE_RESULT_SIZE_1_2
313# if (GCC_VERSION >= 4003)
314# define ATTRIBUTE_RESULT_SIZE_1_2 __attribute__ ((alloc_size (1, 2)))
315# else
316# define ATTRIBUTE_RESULT_SIZE_1_2
317#endif
318#endif
319
320/* Attribute `warn_unused_result' was valid as of gcc 3.3. */
321#ifndef ATTRIBUTE_WARN_UNUSED_RESULT
322# if GCC_VERSION >= 3003
323# define ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
324# else
325# define ATTRIBUTE_WARN_UNUSED_RESULT
326# endif
327#endif
328
f1d95f4b
L
329/* We use __extension__ in some places to suppress -pedantic warnings
330 about GCC extensions. This feature didn't work properly before
331 gcc 2.8. */
332#if GCC_VERSION < 2008
333#define __extension__
334#endif
335
8466c6d4
DD
336/* This is used to declare a const variable which should be visible
337 outside of the current compilation unit. Use it as
338 EXPORTED_CONST int i = 1;
339 This is because the semantics of const are different in C and C++.
340 "extern const" is permitted in C but it looks strange, and gcc
341 warns about it when -Wc++-compat is not used. */
342#ifdef __cplusplus
343#define EXPORTED_CONST extern const
344#else
345#define EXPORTED_CONST const
346#endif
347
006d5c88 348/* Be conservative and only use enum bitfields with C++ or GCC.
1ae0d051
JK
349 FIXME: provide a complete autoconf test for buggy enum bitfields. */
350
006d5c88
DD
351#ifdef __cplusplus
352#define ENUM_BITFIELD(TYPE) enum TYPE
353#elif (GCC_VERSION > 2000)
1ae0d051
JK
354#define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
355#else
356#define ENUM_BITFIELD(TYPE) unsigned int
dd419f3a
L
357#endif
358
26a67918
PA
359#if __cpp_constexpr >= 200704
360#define CONSTEXPR constexpr
361#else
362#define CONSTEXPR
363#endif
364
d118ee37
PA
365/* C++11 adds the ability to add "override" after an implementation of a
366 virtual function in a subclass, to:
367 (A) document that this is an override of a virtual function
368 (B) allow the compiler to issue a warning if it isn't (e.g. a mismatch
369 of the type signature).
370
371 Similarly, it allows us to add a "final" to indicate that no subclass
372 may subsequently override the vfunc.
373
374 Provide OVERRIDE and FINAL as macros, allowing us to get these benefits
375 when compiling with C++11 support, but without requiring C++11.
376
377 For gcc, use "-std=c++11" to enable C++11 support; gcc 6 onwards enables
378 this by default (actually GNU++14). */
379
c48a4d98
NC
380#if defined __cplusplus
381# if __cplusplus >= 201103
382 /* C++11 claims to be available: use it. Final/override were only
383 implemented in 4.7, though. */
384# if GCC_VERSION < 4007
385# define OVERRIDE
386# define FINAL
387# else
388# define OVERRIDE override
389# define FINAL final
390# endif
391# elif GCC_VERSION >= 4007
392 /* G++ 4.7 supports __final in C++98. */
b4f6af8e 393# define OVERRIDE
c48a4d98 394# define FINAL __final
b4f6af8e 395# else
c48a4d98
NC
396 /* No C++11 support; leave the macros empty. */
397# define OVERRIDE
398# define FINAL
b4f6af8e 399# endif
dd419f3a 400#else
c48a4d98 401 /* No C++11 support; leave the macros empty. */
b4f6af8e
PA
402# define OVERRIDE
403# define FINAL
1ae0d051
JK
404#endif
405
26a67918
PA
406/* A macro to disable the copy constructor and assignment operator.
407 When building with C++11 and above, the methods are explicitly
408 deleted, causing a compile-time error if something tries to copy.
409 For C++03, this just declares the methods, causing a link-time
410 error if the methods end up called (assuming you don't
411 define them). For C++03, for best results, place the macro
412 under the private: access specifier, like this,
413
414 class name_lookup
415 {
416 private:
417 DISABLE_COPY_AND_ASSIGN (name_lookup);
418 };
419
420 so that most attempts at copy are caught at compile-time. */
421
422#if __cplusplus >= 201103
423#define DISABLE_COPY_AND_ASSIGN(TYPE) \
424 TYPE (const TYPE&) = delete; \
425 void operator= (const TYPE &) = delete
426 #else
427#define DISABLE_COPY_AND_ASSIGN(TYPE) \
428 TYPE (const TYPE&); \
429 void operator= (const TYPE &)
430#endif /* __cplusplus >= 201103 */
431
52d6785f
DD
432#ifdef __cplusplus
433}
434#endif
435
252b5132 436#endif /* ansidecl.h */