]> git.ipfire.org Git - thirdparty/glibc.git/blame - misc/sys/cdefs.h
Add ersatz _Static_assert on older C hosts
[thirdparty/glibc.git] / misc / sys / cdefs.h
CommitLineData
b168057a 1/* Copyright (C) 1992-2015 Free Software Foundation, Inc.
54d79e99 2 This file is part of the GNU C Library.
28f540f4 3
54d79e99 4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
28f540f4 8
54d79e99
UD
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
28f540f4 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
28f540f4
RM
17
18#ifndef _SYS_CDEFS_H
28f540f4 19#define _SYS_CDEFS_H 1
5107cf1d 20
a6ff34d7
UD
21/* We are almost always included from features.h. */
22#ifndef _FEATURES_H
7688db91
UD
23# include <features.h>
24#endif
25
26/* The GNU libc does not support any K&R compilers or the traditional mode
27 of ISO C compilers anymore. Check for some of the combinations not
28 anymore supported. */
29#if defined __GNUC__ && !defined __STDC__
30# error "You need a ISO C conforming compiler to use the glibc headers"
a6ff34d7 31#endif
28f540f4
RM
32
33/* Some user header file might have defined this before. */
34#undef __P
d112ae30 35#undef __PMT
28f540f4
RM
36
37#ifdef __GNUC__
38
3871f58f
AS
39/* All functions, except those with callbacks or those that
40 synchronize memory, are leaf functions. */
aa78043a
UD
41# if __GNUC_PREREQ (4, 6) && !defined _LIBC
42# define __LEAF , __leaf__
43# define __LEAF_ATTR __attribute__ ((__leaf__))
44# else
45# define __LEAF
46# define __LEAF_ATTR
47# endif
48
dff14448
UD
49/* GCC can always grok prototypes. For C++ programs we add throw()
50 to help it optimize the function calls. But this works only with
f377d022
UD
51 gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
52 as non-throwing using a function attribute since programs can use
53 the -fexceptions options for C code as well. */
e071493f 54# if !defined __cplusplus && __GNUC_PREREQ (3, 3)
49a43d80 55# define __THROW __attribute__ ((__nothrow__ __LEAF))
3871f58f 56# define __THROWNL __attribute__ ((__nothrow__))
49a43d80 57# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
dff14448 58# else
f377d022
UD
59# if defined __cplusplus && __GNUC_PREREQ (2,8)
60# define __THROW throw ()
3871f58f 61# define __THROWNL throw ()
aa78043a 62# define __NTH(fct) __LEAF_ATTR fct throw ()
f377d022
UD
63# else
64# define __THROW
3871f58f 65# define __THROWNL
f377d022
UD
66# define __NTH(fct) fct
67# endif
dff14448 68# endif
4360eafd 69
28f540f4
RM
70#else /* Not GCC. */
71
dfd2257a 72# define __inline /* No inline functions. */
28f540f4 73
9b767d19 74# define __THROW
3871f58f 75# define __THROWNL
f377d022 76# define __NTH(fct) fct
28f540f4
RM
77
78#endif /* GCC. */
79
d19687d6
UD
80/* These two macros are not used in glibc anymore. They are kept here
81 only because some other projects expect the macros to be defined. */
82#define __P(args) args
83#define __PMT(args) args
84
28f540f4
RM
85/* For these things, GCC behaves the ANSI way normally,
86 and the non-ANSI way under -traditional. */
87
7f4e0e58
UD
88#define __CONCAT(x,y) x ## y
89#define __STRING(x) #x
28f540f4
RM
90
91/* This is not a typedef so `const __ptr_t' does the right thing. */
7f4e0e58
UD
92#define __ptr_t void *
93#define __long_double_t long double
857fa1b8
RM
94
95
28f540f4
RM
96/* C++ needs to know that types and declarations are C, not C++. */
97#ifdef __cplusplus
dfd2257a
UD
98# define __BEGIN_DECLS extern "C" {
99# define __END_DECLS }
28f540f4 100#else
dfd2257a
UD
101# define __BEGIN_DECLS
102# define __END_DECLS
28f540f4
RM
103#endif
104
ab95290c 105
c096ab25
UD
106/* The standard library needs the functions from the ISO C90 standard
107 in the std namespace. At the same time we want to be safe for
108 future changes and we include the ISO C99 code in the non-standard
109 namespace __c99. The C++ wrapper header take case of adding the
110 definitions to the global namespace. */
111#if defined __cplusplus && defined _GLIBCPP_USE_NAMESPACES
112# define __BEGIN_NAMESPACE_STD namespace std {
113# define __END_NAMESPACE_STD }
114# define __USING_NAMESPACE_STD(name) using std::name;
115# define __BEGIN_NAMESPACE_C99 namespace __c99 {
116# define __END_NAMESPACE_C99 }
117# define __USING_NAMESPACE_C99(name) using __c99::name;
118#else
119/* For compatibility we do not add the declarations into any
120 namespace. They will end up in the global namespace which is what
121 old code expects. */
122# define __BEGIN_NAMESPACE_STD
123# define __END_NAMESPACE_STD
124# define __USING_NAMESPACE_STD(name)
125# define __BEGIN_NAMESPACE_C99
126# define __END_NAMESPACE_C99
127# define __USING_NAMESPACE_C99(name)
128#endif
129
130
b5cc329c
UD
131/* Fortify support. */
132#define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
133#define __bos0(ptr) __builtin_object_size (ptr, 0)
134
d6cd6bf4
UD
135#if __GNUC_PREREQ (4,3)
136# define __warndecl(name, msg) \
137 extern void name (void) __attribute__((__warning__ (msg)))
138# define __warnattr(msg) __attribute__((__warning__ (msg)))
139# define __errordecl(name, msg) \
140 extern void name (void) __attribute__((__error__ (msg)))
141#else
142# define __warndecl(name, msg) extern void name (void)
143# define __warnattr(msg)
144# define __errordecl(name, msg) extern void name (void)
145#endif
b5cc329c 146
a1620a4c
UD
147/* Support for flexible arrays. */
148#if __GNUC_PREREQ (2,97)
149/* GCC 2.97 supports C99 flexible array members. */
150# define __flexarr []
151#else
152# ifdef __GNUC__
153# define __flexarr [0]
154# else
8ab5926a 155# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
a1620a4c
UD
156# define __flexarr []
157# else
158/* Some other non-C99 compiler. Approximate with [1]. */
159# define __flexarr [1]
160# endif
161# endif
162#endif
163
164
01cad722
UD
165/* __asm__ ("xyz") is used throughout the headers to rename functions
166 at the assembly language level. This is wrapped by the __REDIRECT
167 macro, in order to support compilers that can do this some other
168 way. When compilers don't support asm-names at all, we have to do
169 preprocessor tricks instead (which don't have exactly the right
170 semantics, but it's the best we can do).
171
172 Example:
fbedbe9d 173 int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
01cad722
UD
174
175#if defined __GNUC__ && __GNUC__ >= 2
176
5408c757 177# define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
05f4d5cd
UD
178# ifdef __cplusplus
179# define __REDIRECT_NTH(name, proto, alias) \
180 name proto __THROW __asm__ (__ASMNAME (#alias))
edc5984d
AS
181# define __REDIRECT_NTHNL(name, proto, alias) \
182 name proto __THROWNL __asm__ (__ASMNAME (#alias))
05f4d5cd
UD
183# else
184# define __REDIRECT_NTH(name, proto, alias) \
f377d022 185 name proto __asm__ (__ASMNAME (#alias)) __THROW
edc5984d
AS
186# define __REDIRECT_NTHNL(name, proto, alias) \
187 name proto __asm__ (__ASMNAME (#alias)) __THROWNL
05f4d5cd 188# endif
5408c757
UD
189# define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
190# define __ASMNAME2(prefix, cname) __STRING (prefix) cname
01cad722
UD
191
192/*
193#elif __SOME_OTHER_COMPILER__
194
5408c757
UD
195# define __REDIRECT(name, proto, alias) name proto; \
196 _Pragma("let " #name " = " #alias)
01cad722
UD
197*/
198#endif
199
200/* GCC has various useful declarations that can be made with the
28f540f4 201 `__attribute__' syntax. All of the ways we use this do fine if
01cad722 202 they are omitted for compilers that don't understand it. */
dfd2257a 203#if !defined __GNUC__ || __GNUC__ < 2
e9e9b245 204# define __attribute__(xyz) /* Ignore */
ae177b9c
UD
205#endif
206
e9e9b245
UD
207/* At some point during the gcc 2.96 development the `malloc' attribute
208 for functions was introduced. We don't want to use it unconditionally
209 (although this would be possible) since it generates warnings. */
ae177b9c
UD
210#if __GNUC_PREREQ (2,96)
211# define __attribute_malloc__ __attribute__ ((__malloc__))
212#else
213# define __attribute_malloc__ /* Ignore */
01cad722 214#endif
2f6d1f1b 215
2f62b9ee
MF
216/* Tell the compiler which arguments to an allocation function
217 indicate the size of the allocation. */
218#if __GNUC_PREREQ (4, 3)
219# define __attribute_alloc_size__(params) \
220 __attribute__ ((__alloc_size__ params))
221#else
222# define __attribute_alloc_size__(params) /* Ignore. */
223#endif
224
ca5a4c3c
AJ
225/* At some point during the gcc 2.96 development the `pure' attribute
226 for functions was introduced. We don't want to use it unconditionally
227 (although this would be possible) since it generates warnings. */
228#if __GNUC_PREREQ (2,96)
229# define __attribute_pure__ __attribute__ ((__pure__))
230#else
231# define __attribute_pure__ /* Ignore */
232#endif
233
295e904f
MP
234/* This declaration tells the compiler that the value is constant. */
235#if __GNUC_PREREQ (2,5)
236# define __attribute_const__ __attribute__ ((__const__))
237#else
238# define __attribute_const__ /* Ignore */
239#endif
240
d3640b91
UD
241/* At some point during the gcc 3.1 development the `used' attribute
242 for functions was introduced. We don't want to use it unconditionally
243 (although this would be possible) since it generates warnings. */
244#if __GNUC_PREREQ (3,1)
245# define __attribute_used__ __attribute__ ((__used__))
fb23eb25 246# define __attribute_noinline__ __attribute__ ((__noinline__))
d3640b91
UD
247#else
248# define __attribute_used__ __attribute__ ((__unused__))
fb23eb25 249# define __attribute_noinline__ /* Ignore */
d3640b91
UD
250#endif
251
3b7ed871
UD
252/* gcc allows marking deprecated functions. */
253#if __GNUC_PREREQ (3,2)
254# define __attribute_deprecated__ __attribute__ ((__deprecated__))
255#else
256# define __attribute_deprecated__ /* Ignore */
257#endif
258
ca8d5a5f
UD
259/* At some point during the gcc 2.8 development the `format_arg' attribute
260 for functions was introduced. We don't want to use it unconditionally
f369623d
UD
261 (although this would be possible) since it generates warnings.
262 If several `format_arg' attributes are given for the same function, in
263 gcc-3.0 and older, all but the last one are ignored. In newer gccs,
264 all designated arguments are considered. */
ca8d5a5f
UD
265#if __GNUC_PREREQ (2,8)
266# define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
267#else
268# define __attribute_format_arg__(x) /* Ignore */
269#endif
270
66e23ba1
UD
271/* At some point during the gcc 2.97 development the `strfmon' format
272 attribute for functions was introduced. We don't want to use it
273 unconditionally (although this would be possible) since it
274 generates warnings. */
275#if __GNUC_PREREQ (2,97)
276# define __attribute_format_strfmon__(a,b) \
277 __attribute__ ((__format__ (__strfmon__, a, b)))
278#else
279# define __attribute_format_strfmon__(a,b) /* Ignore */
280#endif
281
8a1f658b
UD
282/* The nonull function attribute allows to mark pointer parameters which
283 must not be NULL. */
284#if __GNUC_PREREQ (3,3)
285# define __nonnull(params) __attribute__ ((__nonnull__ params))
286#else
287# define __nonnull(params)
288#endif
289
5cf53cc2
UD
290/* If fortification mode, we warn about unused results of certain
291 function calls which can lead to problems. */
9ee4c017
UD
292#if __GNUC_PREREQ (3,4)
293# define __attribute_warn_unused_result__ \
294 __attribute__ ((__warn_unused_result__))
295# if __USE_FORTIFY_LEVEL > 0
296# define __wur __attribute_warn_unused_result__
297# endif
5cf53cc2 298#else
9ee4c017
UD
299# define __attribute_warn_unused_result__ /* empty */
300#endif
301#ifndef __wur
5cf53cc2
UD
302# define __wur /* Ignore */
303#endif
304
88764ae2
UD
305/* Forces a function to be always inlined. */
306#if __GNUC_PREREQ (3,2)
307# define __always_inline __inline __attribute__ ((__always_inline__))
308#else
309# define __always_inline __inline
310#endif
311
5ac3ea17
MP
312/* Associate error messages with the source location of the call site rather
313 than with the source location inside the function. */
314#if __GNUC_PREREQ (4,3)
315# define __attribute_artificial__ __attribute__ ((__artificial__))
316#else
317# define __attribute_artificial__ /* Ignore */
318#endif
319
884ddc50
SP
320/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
321 inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__
322 or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
323 older than 4.3 may define these macros and still not guarantee GNU inlining
602f80ec
SP
324 semantics.
325
326 clang++ identifies itself as gcc-4.2, but has support for GNU inlining
327 semantics, that can be checked fot by using the __GNUC_STDC_INLINE_ and
328 __GNUC_GNU_INLINE__ macro definitions. */
329#if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
330 || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
331 || defined __GNUC_GNU_INLINE__)))
884ddc50 332# if defined __GNUC_STDC_INLINE__ || defined __cplusplus
de1c3ebb 333# define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
5ac3ea17 334# define __extern_always_inline \
b037a293 335 extern __always_inline __attribute__ ((__gnu_inline__))
de1c3ebb
UD
336# else
337# define __extern_inline extern __inline
5ac3ea17 338# define __extern_always_inline extern __always_inline
de1c3ebb 339# endif
884ddc50
SP
340#endif
341
342#ifdef __extern_always_inline
343# define __fortify_function __extern_always_inline __attribute_artificial__
de1c3ebb
UD
344#endif
345
346/* GCC 4.3 and above allow passing all anonymous arguments of an
347 __extern_always_inline function to some other vararg function. */
3dd79d63 348#if __GNUC_PREREQ (4,3)
de1c3ebb 349# define __va_arg_pack() __builtin_va_arg_pack ()
3a50811c 350# define __va_arg_pack_len() __builtin_va_arg_pack_len ()
b037a293
UD
351#endif
352
8325d82c
UD
353/* It is possible to compile containing GCC extensions even if GCC is
354 run in pedantic mode if the uses are carefully marked using the
355 `__extension__' keyword. But this is not generally available before
356 version 2.8. */
4360eafd 357#if !__GNUC_PREREQ (2,8)
8325d82c 358# define __extension__ /* Ignore */
8325d82c
UD
359#endif
360
a6ff34d7 361/* __restrict is known in EGCS 1.2 and above. */
4360eafd 362#if !__GNUC_PREREQ (2,92)
a6ff34d7 363# define __restrict /* Ignore */
a6ff34d7 364#endif
2f6d1f1b 365
98cbe360
UD
366/* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
367 array_name[restrict]
b912ca11 368 GCC 3.1 supports this. */
852d75f9 369#if __GNUC_PREREQ (3,1) && !defined __GNUG__
b912ca11
UD
370# define __restrict_arr __restrict
371#else
372# ifdef __GNUC__
373# define __restrict_arr /* Not supported in old GCC. */
374# else
375# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
376# define __restrict_arr restrict
377# else
378/* Some other non-C99 compiler. */
379# define __restrict_arr /* Not supported. */
380# endif
381# endif
382#endif
98cbe360 383
4af3879c 384#if __GNUC__ >= 3
4858fa2a
RM
385# define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
386# define __glibc_likely(cond) __builtin_expect ((cond), 1)
4af3879c 387#else
4858fa2a
RM
388# define __glibc_unlikely(cond) (cond)
389# define __glibc_likely(cond) (cond)
4af3879c
SP
390#endif
391
d12704c7
SP
392#if (!defined _Noreturn \
393 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
394 && !__GNUC_PREREQ (4,7))
c4c41244
PE
395# if __GNUC_PREREQ (2,8)
396# define _Noreturn __attribute__ ((__noreturn__))
397# else
398# define _Noreturn
399# endif
400#endif
401
3999d26e
PE
402#if (!defined _Static_assert && !defined __cplusplus \
403 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
404 && (!__GNUC_PREREQ (4, 6) || defined __STRICT_ANSI__))
405# define _Static_assert(expr, diagnostic) \
406 extern int (*__Static_assert_function (void)) \
407 [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
408#endif
409
c6251f03
RM
410#include <bits/wordsize.h>
411
412#if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
413# define __LDBL_COMPAT 1
414# ifdef __REDIRECT
415# define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
416# define __LDBL_REDIR(name, proto) \
417 __LDBL_REDIR1 (name, proto, __nldbl_##name)
418# define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
419# define __LDBL_REDIR_NTH(name, proto) \
420 __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
54e98f69
RM
421# define __LDBL_REDIR1_DECL(name, alias) \
422 extern __typeof (name) name __asm (__ASMNAME (#alias));
c6251f03 423# define __LDBL_REDIR_DECL(name) \
54e98f69 424 extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
ac97dec1
UD
425# define __REDIRECT_LDBL(name, proto, alias) \
426 __LDBL_REDIR1 (name, proto, __nldbl_##alias)
427# define __REDIRECT_NTH_LDBL(name, proto, alias) \
428 __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
c6251f03
RM
429# endif
430#endif
431#if !defined __LDBL_COMPAT || !defined __REDIRECT
432# define __LDBL_REDIR1(name, proto, alias) name proto
433# define __LDBL_REDIR(name, proto) name proto
434# define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
435# define __LDBL_REDIR_NTH(name, proto) name proto __THROW
436# define __LDBL_REDIR_DECL(name)
ac97dec1
UD
437# ifdef __REDIRECT
438# define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
439# define __REDIRECT_NTH_LDBL(name, proto, alias) \
440 __REDIRECT_NTH (name, proto, alias)
441# endif
c6251f03
RM
442#endif
443
28f540f4 444#endif /* sys/cdefs.h */