]>
git.ipfire.org Git - thirdparty/glibc.git/blob - misc/sys/cdefs.h
6b9763a92a7e42974581a3811fcb1b5a22313da2
1 /* Copyright (C) 1992-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
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.
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
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
19 #define _SYS_CDEFS_H 1
21 /* We are almost always included from features.h. */
23 # include <features.h>
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
29 #if defined __GNUC__ && !defined __STDC__
30 # error "You need a ISO C conforming compiler to use the glibc headers"
33 /* Some user header file might have defined this before. */
39 /* All functions, except those with callbacks or those that
40 synchronize memory, are leaf functions. */
41 # if __GNUC_PREREQ (4, 6) && !defined _LIBC
42 # define __LEAF , __leaf__
43 # define __LEAF_ATTR __attribute__ ((__leaf__))
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
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. */
54 # if !defined __cplusplus && __GNUC_PREREQ (3, 3)
55 # define __THROW __attribute__ ((__nothrow__ __LEAF))
56 # define __THROWNL __attribute__ ((__nothrow__))
57 # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
58 # define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
60 # if defined __cplusplus && __GNUC_PREREQ (2,8)
61 # if __cplusplus >= 201103L
62 # define __THROW noexcept (true)
64 # define __THROW throw ()
66 # define __THROWNL __THROW
67 # define __NTH(fct) __LEAF_ATTR fct __THROW
68 # define __NTHNL(fct) fct __THROW
72 # define __NTH(fct) fct
73 # define __NTHNL(fct) fct
79 # if (defined __cplusplus \
80 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
81 # define __inline inline
83 # define __inline /* No inline functions. */
88 # define __NTH(fct) fct
92 /* Compilers that are not clang may object to
93 #if defined __clang__ && __has_extension(...)
94 even though they do not need to evaluate the right-hand side of the &&. */
95 #if defined __clang__ && defined __has_extension
96 # define __glibc_clang_has_extension(ext) __has_extension (ext)
98 # define __glibc_clang_has_extension(ext) 0
101 /* These two macros are not used in glibc anymore. They are kept here
102 only because some other projects expect the macros to be defined. */
103 #define __P(args) args
104 #define __PMT(args) args
106 /* For these things, GCC behaves the ANSI way normally,
107 and the non-ANSI way under -traditional. */
109 #define __CONCAT(x,y) x ## y
110 #define __STRING(x) #x
112 /* This is not a typedef so `const __ptr_t' does the right thing. */
113 #define __ptr_t void *
116 /* C++ needs to know that types and declarations are C, not C++. */
118 # define __BEGIN_DECLS extern "C" {
119 # define __END_DECLS }
121 # define __BEGIN_DECLS
126 /* Fortify support. */
127 #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
128 #define __bos0(ptr) __builtin_object_size (ptr, 0)
130 #if __GNUC_PREREQ (4,3)
131 # define __warndecl(name, msg) \
132 extern void name (void) __attribute__((__warning__ (msg)))
133 # define __warnattr(msg) __attribute__((__warning__ (msg)))
134 # define __errordecl(name, msg) \
135 extern void name (void) __attribute__((__error__ (msg)))
137 # define __warndecl(name, msg) extern void name (void)
138 # define __warnattr(msg)
139 # define __errordecl(name, msg) extern void name (void)
142 /* Support for flexible arrays.
143 Headers that should use flexible arrays only if they're "real"
144 (e.g. only if they won't affect sizeof()) should test
145 #if __glibc_c99_flexarr_available. */
146 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
147 # define __flexarr []
148 # define __glibc_c99_flexarr_available 1
149 #elif __GNUC_PREREQ (2,97)
150 /* GCC 2.97 supports C99 flexible array members as an extension,
151 even when in C89 mode or compiling C++ (any version). */
152 # define __flexarr []
153 # define __glibc_c99_flexarr_available 1
154 #elif defined __GNUC__
155 /* Pre-2.97 GCC did not support C99 flexible arrays but did have
156 an equivalent extension with slightly different notation. */
157 # define __flexarr [0]
158 # define __glibc_c99_flexarr_available 1
160 /* Some other non-C99 compiler. Approximate with [1]. */
161 # define __flexarr [1]
162 # define __glibc_c99_flexarr_available 0
166 /* __asm__ ("xyz") is used throughout the headers to rename functions
167 at the assembly language level. This is wrapped by the __REDIRECT
168 macro, in order to support compilers that can do this some other
169 way. When compilers don't support asm-names at all, we have to do
170 preprocessor tricks instead (which don't have exactly the right
171 semantics, but it's the best we can do).
174 int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
176 #if defined __GNUC__ && __GNUC__ >= 2
178 # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
180 # define __REDIRECT_NTH(name, proto, alias) \
181 name proto __THROW __asm__ (__ASMNAME (#alias))
182 # define __REDIRECT_NTHNL(name, proto, alias) \
183 name proto __THROWNL __asm__ (__ASMNAME (#alias))
185 # define __REDIRECT_NTH(name, proto, alias) \
186 name proto __asm__ (__ASMNAME (#alias)) __THROW
187 # define __REDIRECT_NTHNL(name, proto, alias) \
188 name proto __asm__ (__ASMNAME (#alias)) __THROWNL
190 # define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
191 # define __ASMNAME2(prefix, cname) __STRING (prefix) cname
194 #elif __SOME_OTHER_COMPILER__
196 # define __REDIRECT(name, proto, alias) name proto; \
197 _Pragma("let " #name " = " #alias)
201 /* GCC has various useful declarations that can be made with the
202 `__attribute__' syntax. All of the ways we use this do fine if
203 they are omitted for compilers that don't understand it. */
204 #if !defined __GNUC__ || __GNUC__ < 2
205 # define __attribute__(xyz) /* Ignore */
208 /* At some point during the gcc 2.96 development the `malloc' attribute
209 for functions was introduced. We don't want to use it unconditionally
210 (although this would be possible) since it generates warnings. */
211 #if __GNUC_PREREQ (2,96)
212 # define __attribute_malloc__ __attribute__ ((__malloc__))
214 # define __attribute_malloc__ /* Ignore */
217 /* Tell the compiler which arguments to an allocation function
218 indicate the size of the allocation. */
219 #if __GNUC_PREREQ (4, 3)
220 # define __attribute_alloc_size__(params) \
221 __attribute__ ((__alloc_size__ params))
223 # define __attribute_alloc_size__(params) /* Ignore. */
226 /* At some point during the gcc 2.96 development the `pure' attribute
227 for functions was introduced. We don't want to use it unconditionally
228 (although this would be possible) since it generates warnings. */
229 #if __GNUC_PREREQ (2,96)
230 # define __attribute_pure__ __attribute__ ((__pure__))
232 # define __attribute_pure__ /* Ignore */
235 /* This declaration tells the compiler that the value is constant. */
236 #if __GNUC_PREREQ (2,5)
237 # define __attribute_const__ __attribute__ ((__const__))
239 # define __attribute_const__ /* Ignore */
242 /* At some point during the gcc 3.1 development the `used' attribute
243 for functions was introduced. We don't want to use it unconditionally
244 (although this would be possible) since it generates warnings. */
245 #if __GNUC_PREREQ (3,1)
246 # define __attribute_used__ __attribute__ ((__used__))
247 # define __attribute_noinline__ __attribute__ ((__noinline__))
249 # define __attribute_used__ __attribute__ ((__unused__))
250 # define __attribute_noinline__ /* Ignore */
253 /* Since version 3.2, gcc allows marking deprecated functions. */
254 #if __GNUC_PREREQ (3,2)
255 # define __attribute_deprecated__ __attribute__ ((__deprecated__))
257 # define __attribute_deprecated__ /* Ignore */
260 /* Since version 4.5, gcc also allows one to specify the message printed
261 when a deprecated function is used. clang claims to be gcc 4.2, but
262 may also support this feature. */
263 #if __GNUC_PREREQ (4,5) \
264 || __glibc_clang_has_extension (__attribute_deprecated_with_message__)
265 # define __attribute_deprecated_msg__(msg) \
266 __attribute__ ((__deprecated__ (msg)))
268 # define __attribute_deprecated_msg__(msg) __attribute_deprecated__
271 /* At some point during the gcc 2.8 development the `format_arg' attribute
272 for functions was introduced. We don't want to use it unconditionally
273 (although this would be possible) since it generates warnings.
274 If several `format_arg' attributes are given for the same function, in
275 gcc-3.0 and older, all but the last one are ignored. In newer gccs,
276 all designated arguments are considered. */
277 #if __GNUC_PREREQ (2,8)
278 # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
280 # define __attribute_format_arg__(x) /* Ignore */
283 /* At some point during the gcc 2.97 development the `strfmon' format
284 attribute for functions was introduced. We don't want to use it
285 unconditionally (although this would be possible) since it
286 generates warnings. */
287 #if __GNUC_PREREQ (2,97)
288 # define __attribute_format_strfmon__(a,b) \
289 __attribute__ ((__format__ (__strfmon__, a, b)))
291 # define __attribute_format_strfmon__(a,b) /* Ignore */
294 /* The nonull function attribute allows to mark pointer parameters which
296 #if __GNUC_PREREQ (3,3)
297 # define __nonnull(params) __attribute__ ((__nonnull__ params))
299 # define __nonnull(params)
302 /* If fortification mode, we warn about unused results of certain
303 function calls which can lead to problems. */
304 #if __GNUC_PREREQ (3,4)
305 # define __attribute_warn_unused_result__ \
306 __attribute__ ((__warn_unused_result__))
307 # if __USE_FORTIFY_LEVEL > 0
308 # define __wur __attribute_warn_unused_result__
311 # define __attribute_warn_unused_result__ /* empty */
314 # define __wur /* Ignore */
317 /* Forces a function to be always inlined. */
318 #if __GNUC_PREREQ (3,2)
319 /* The Linux kernel defines __always_inline in stddef.h (283d7573), and
320 it conflicts with this definition. Therefore undefine it first to
321 allow either header to be included first. */
322 # undef __always_inline
323 # define __always_inline __inline __attribute__ ((__always_inline__))
325 # undef __always_inline
326 # define __always_inline __inline
329 /* Associate error messages with the source location of the call site rather
330 than with the source location inside the function. */
331 #if __GNUC_PREREQ (4,3)
332 # define __attribute_artificial__ __attribute__ ((__artificial__))
334 # define __attribute_artificial__ /* Ignore */
337 /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
338 inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__
339 or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
340 older than 4.3 may define these macros and still not guarantee GNU inlining
343 clang++ identifies itself as gcc-4.2, but has support for GNU inlining
344 semantics, that can be checked for by using the __GNUC_STDC_INLINE_ and
345 __GNUC_GNU_INLINE__ macro definitions. */
346 #if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
347 || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
348 || defined __GNUC_GNU_INLINE__)))
349 # if defined __GNUC_STDC_INLINE__ || defined __cplusplus
350 # define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
351 # define __extern_always_inline \
352 extern __always_inline __attribute__ ((__gnu_inline__))
354 # define __extern_inline extern __inline
355 # define __extern_always_inline extern __always_inline
359 #ifdef __extern_always_inline
360 # define __fortify_function __extern_always_inline __attribute_artificial__
363 /* GCC 4.3 and above allow passing all anonymous arguments of an
364 __extern_always_inline function to some other vararg function. */
365 #if __GNUC_PREREQ (4,3)
366 # define __va_arg_pack() __builtin_va_arg_pack ()
367 # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
370 /* It is possible to compile containing GCC extensions even if GCC is
371 run in pedantic mode if the uses are carefully marked using the
372 `__extension__' keyword. But this is not generally available before
374 #if !__GNUC_PREREQ (2,8)
375 # define __extension__ /* Ignore */
378 /* __restrict is known in EGCS 1.2 and above. */
379 #if !__GNUC_PREREQ (2,92)
380 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
381 # define __restrict restrict
383 # define __restrict /* Ignore */
387 /* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
389 GCC 3.1 supports this. */
390 #if __GNUC_PREREQ (3,1) && !defined __GNUG__
391 # define __restrict_arr __restrict
394 # define __restrict_arr /* Not supported in old GCC. */
396 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
397 # define __restrict_arr restrict
399 /* Some other non-C99 compiler. */
400 # define __restrict_arr /* Not supported. */
406 # define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
407 # define __glibc_likely(cond) __builtin_expect ((cond), 1)
409 # define __glibc_unlikely(cond) (cond)
410 # define __glibc_likely(cond) (cond)
413 #ifdef __has_attribute
414 # define __glibc_has_attribute(attr) __has_attribute (attr)
416 # define __glibc_has_attribute(attr) 0
419 #if (!defined _Noreturn \
420 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
421 && !__GNUC_PREREQ (4,7))
422 # if __GNUC_PREREQ (2,8)
423 # define _Noreturn __attribute__ ((__noreturn__))
429 #if __GNUC_PREREQ (8, 0)
430 /* Describes a char array whose address can safely be passed as the first
431 argument to strncpy and strncat, as the char array is not necessarily
432 a NUL-terminated string. */
433 # define __attribute_nonstring__ __attribute__ ((__nonstring__))
435 # define __attribute_nonstring__
438 /* Undefine (also defined in libc-symbols.h). */
439 #undef __attribute_copy__
440 #if __GNUC_PREREQ (9, 0)
441 /* Copies attributes from the declaration or type referenced by
443 # define __attribute_copy__(arg) __attribute__ ((__copy__ (arg)))
445 # define __attribute_copy__(arg)
448 #if (!defined _Static_assert && !defined __cplusplus \
449 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
450 && (!__GNUC_PREREQ (4, 6) || defined __STRICT_ANSI__))
451 # define _Static_assert(expr, diagnostic) \
452 extern int (*__Static_assert_function (void)) \
453 [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
456 #include <bits/wordsize.h>
457 #include <bits/long-double.h>
459 #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
462 /* Alias name defined automatically. */
463 # define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
464 # define __LDBL_REDIR_DECL(name) \
465 extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
467 /* Alias name defined automatically, with leading underscores. */
468 # define __LDBL_REDIR2_DECL(name) \
469 extern __typeof (__##name) __##name \
470 __asm (__ASMNAME ("__" #name "ieee128"));
472 /* Alias name defined manually. */
473 # define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1
474 # define __LDBL_REDIR1_DECL(name, alias) \
475 extern __typeof (name) name __asm (__ASMNAME (#alias));
477 # define __LDBL_REDIR1_NTH(name, proto, alias) \
478 __REDIRECT_NTH (name, proto, alias)
479 # define __REDIRECT_NTH_LDBL(name, proto, alias) \
480 __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128)
483 # define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl
484 # define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth
487 _Static_assert (0, "IEEE 128-bits long double requires redirection on this platform");
489 #elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
490 # define __LDBL_COMPAT 1
492 # define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
493 # define __LDBL_REDIR(name, proto) \
494 __LDBL_REDIR1 (name, proto, __nldbl_##name)
495 # define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
496 # define __LDBL_REDIR_NTH(name, proto) \
497 __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
498 # define __LDBL_REDIR2_DECL(name) \
499 extern __typeof (__##name) __##name __asm (__ASMNAME ("__nldbl___" #name));
500 # define __LDBL_REDIR1_DECL(name, alias) \
501 extern __typeof (name) name __asm (__ASMNAME (#alias));
502 # define __LDBL_REDIR_DECL(name) \
503 extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
504 # define __REDIRECT_LDBL(name, proto, alias) \
505 __LDBL_REDIR1 (name, proto, __nldbl_##alias)
506 # define __REDIRECT_NTH_LDBL(name, proto, alias) \
507 __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
510 #if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) \
511 || !defined __REDIRECT
512 # define __LDBL_REDIR1(name, proto, alias) name proto
513 # define __LDBL_REDIR(name, proto) name proto
514 # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
515 # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
516 # define __LDBL_REDIR2_DECL(name)
517 # define __LDBL_REDIR_DECL(name)
519 # define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
520 # define __REDIRECT_NTH_LDBL(name, proto, alias) \
521 __REDIRECT_NTH (name, proto, alias)
525 /* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is
526 intended for use in preprocessor macros.
528 Note: MESSAGE must be a _single_ string; concatenation of string
529 literals is not supported. */
530 #if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
531 # define __glibc_macro_warning1(message) _Pragma (#message)
532 # define __glibc_macro_warning(message) \
533 __glibc_macro_warning1 (GCC warning message)
535 # define __glibc_macro_warning(msg)
538 /* Generic selection (ISO C11) is a C-only feature, available in GCC
539 since version 4.9. Previous versions do not provide generic
540 selection, even though they might set __STDC_VERSION__ to 201112L,
541 when in -std=c11 mode. Thus, we must check for !defined __GNUC__
542 when testing __STDC_VERSION__ for generic selection support.
543 On the other hand, Clang also defines __GNUC__, so a clang-specific
544 check is required to enable the use of generic selection. */
545 #if !defined __cplusplus \
546 && (__GNUC_PREREQ (4, 9) \
547 || __glibc_clang_has_extension (c_generic_selections) \
548 || (!defined __GNUC__ && defined __STDC_VERSION__ \
549 && __STDC_VERSION__ >= 201112L))
550 # define __HAVE_GENERIC_SELECTION 1
552 # define __HAVE_GENERIC_SELECTION 0
555 #if __GNUC_PREREQ (10, 0)
556 /* Designates a 1-based positional argument ref-index of pointer type
557 that can be used to access size-index elements of the pointed-to
558 array according to access mode, or at least one element when
559 size-index is not provided:
560 access (access-mode, <ref-index> [, <size-index>]) */
561 #define __attr_access(x) __attribute__ ((__access__ x))
563 # define __attr_access(x)
566 #endif /* sys/cdefs.h */