nptl: remove sysdep-cancel ASM macros, convert to C
[uclibc-ng.git] / include / sys / cdefs.h
blob6cd38114b87b35a561743e9219f22ee340e26d86
1 /* Copyright (C) 1992-2001, 2002, 2004, 2005, 2006, 2007
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _SYS_CDEFS_H
20 #define _SYS_CDEFS_H 1
22 /* We are almost always included from features.h. */
23 #ifndef _FEATURES_H
24 # include <features.h>
25 #endif
27 /* The GNU libc does not support any K&R compilers or the traditional mode
28 of ISO C compilers anymore. Check for some of the combinations not
29 anymore supported. */
30 #if defined __GNUC__ && !defined __STDC__
31 # error "You need a ISO C conforming compiler to use the glibc headers"
32 #endif
34 /* Some user header file might have defined this before. */
35 #undef __P
36 #undef __PMT
38 #ifdef __GNUC__
40 /* All functions, except those with callbacks or those that
41 synchronize memory, are leaf functions. */
42 # if __GNUC_PREREQ (4, 6) && !defined _LIBC
43 # define __LEAF , __leaf__
44 # define __LEAF_ATTR __attribute__ ((__leaf__))
45 # else
46 # define __LEAF
47 # define __LEAF_ATTR
48 # endif
50 /* GCC can always grok prototypes. For C++ programs we add throw()
51 to help it optimize the function calls. But this works only with
52 gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
53 as non-throwing using a function attribute since programs can use
54 the -fexceptions options for C code as well. */
55 # if !defined __cplusplus && __GNUC_PREREQ (3, 3)
56 # define __THROW __attribute__ ((__nothrow__ __LEAF))
57 # define __THROWNL __attribute__ ((__nothrow__))
58 # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
59 # else
60 # if defined __cplusplus && __GNUC_PREREQ (2,8)
61 # define __THROW throw ()
62 # define __THROWNL throw ()
63 # define __NTH(fct) __LEAF_ATTR fct throw ()
64 # else
65 # define __THROW
66 # define __THROWNL
67 # define __NTH(fct) fct
68 # endif
69 # endif
71 #else /* Not GCC. */
73 # define __inline /* No inline functions. */
75 # define __THROW
76 # define __THROWNL
77 # define __NTH(fct) fct
79 #endif /* GCC. */
81 /* These two macros are not used in glibc anymore. They are kept here
82 only because some other projects expect the macros to be defined. */
83 #define __P(args) args
84 #define __PMT(args) args
86 /* For these things, GCC behaves the ANSI way normally,
87 and the non-ANSI way under -traditional. */
89 #define __CONCAT(x,y) x ## y
90 #define __STRING(x) #x
92 /* This is not a typedef so `const __ptr_t' does the right thing. */
93 #define __ptr_t void *
94 #define __long_double_t long double
97 /* C++ needs to know that types and declarations are C, not C++. */
98 #ifdef __cplusplus
99 # define __BEGIN_DECLS extern "C" {
100 # define __END_DECLS }
101 #else
102 # define __BEGIN_DECLS
103 # define __END_DECLS
104 #endif
107 /* The standard library needs the functions from the ISO C90 standard
108 in the std namespace. At the same time we want to be safe for
109 future changes and we include the ISO C99 code in the non-standard
110 namespace __c99. The C++ wrapper header take case of adding the
111 definitions to the global namespace. */
112 #if defined __cplusplus && defined _GLIBCPP_USE_NAMESPACES
113 # define __BEGIN_NAMESPACE_STD namespace std {
114 # define __END_NAMESPACE_STD }
115 # define __USING_NAMESPACE_STD(name) using std::name;
116 # define __BEGIN_NAMESPACE_C99 namespace __c99 {
117 # define __END_NAMESPACE_C99 }
118 # define __USING_NAMESPACE_C99(name) using __c99::name;
119 #else
120 /* For compatibility we do not add the declarations into any
121 namespace. They will end up in the global namespace which is what
122 old code expects. */
123 # define __BEGIN_NAMESPACE_STD
124 # define __END_NAMESPACE_STD
125 # define __USING_NAMESPACE_STD(name)
126 # define __BEGIN_NAMESPACE_C99
127 # define __END_NAMESPACE_C99
128 # define __USING_NAMESPACE_C99(name)
129 #endif
132 /* Fortify support. */
133 #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
134 #define __bos0(ptr) __builtin_object_size (ptr, 0)
136 #if __GNUC_PREREQ (4,3)
137 # define __warndecl(name, msg) \
138 extern void name (void) __attribute__((__warning__ (msg)))
139 # define __warnattr(msg) __attribute__((__warning__ (msg)))
140 # define __errordecl(name, msg) \
141 extern void name (void) __attribute__((__error__ (msg)))
142 #else
143 # define __warndecl(name, msg) extern void name (void)
144 # define __warnattr(msg)
145 # define __errordecl(name, msg) extern void name (void)
146 #endif
148 /* Support for flexible arrays. */
149 #if __GNUC_PREREQ (2,97)
150 /* GCC 2.97 supports C99 flexible array members. */
151 # define __flexarr []
152 #else
153 # ifdef __GNUC__
154 # define __flexarr [0]
155 # else
156 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
157 # define __flexarr []
158 # else
159 /* Some other non-C99 compiler. Approximate with [1]. */
160 # define __flexarr [1]
161 # endif
162 # endif
163 #endif
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).
173 Example:
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))
179 # ifdef __cplusplus
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))
184 # else
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
189 # endif
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)
199 #endif
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 */
206 #endif
208 /* We make this a no-op unless it can be used as both a variable and
209 a type attribute. gcc 2.8 is known to support both. */
210 #if __GNUC_PREREQ (2,8)
211 # define __attribute_aligned__(size) __attribute__ ((__aligned__ (size)))
212 #else
213 # define __attribute_aligned__(size) /* Ignore */
214 #endif
216 /* At some point during the gcc 2.96 development the `malloc' attribute
217 for functions was introduced. We don't want to use it unconditionally
218 (although this would be possible) since it generates warnings. */
219 #if __GNUC_PREREQ (2,96)
220 # define __attribute_malloc__ __attribute__ ((__malloc__))
221 #else
222 # define __attribute_malloc__ /* Ignore */
223 #endif
225 /* Tell the compiler which arguments to an allocation function
226 indicate the size of the allocation. */
227 #if __GNUC_PREREQ (4, 3)
228 # define __attribute_alloc_size__(params) \
229 __attribute__ ((__alloc_size__ params))
230 #else
231 # define __attribute_alloc_size__(params) /* Ignore. */
232 #endif
234 /* At some point during the gcc 2.96 development the `pure' attribute
235 for functions was introduced. We don't want to use it unconditionally
236 (although this would be possible) since it generates warnings. */
237 #if __GNUC_PREREQ (2,96)
238 # define __attribute_pure__ __attribute__ ((__pure__))
239 #else
240 # define __attribute_pure__ /* Ignore */
241 #endif
243 #if __GNUC_PREREQ (2,96)
244 # define __attribute_const__ __attribute__((__const__))
245 #else
246 # define __attribute_const__ /* unimplemented */
247 #endif
249 /* At some point during the gcc 3.1 development the `used' attribute
250 for functions was introduced. We don't want to use it unconditionally
251 (although this would be possible) since it generates warnings. */
252 #if __GNUC_PREREQ (3,1)
253 # define __attribute_used__ __attribute__ ((__used__))
254 # define __attribute_noinline__ __attribute__ ((__noinline__))
255 #else
256 # define __attribute_used__ __attribute__ ((__unused__))
257 # define __attribute_noinline__ /* Ignore */
258 #endif
260 /* gcc allows marking deprecated functions. */
261 #if __GNUC_PREREQ (3,2) && !defined(__UCLIBC_HIDE_DEPRECATED__)
262 # define __attribute_deprecated__ __attribute__ ((__deprecated__))
263 #else
264 # define __attribute_deprecated__ /* Ignore */
265 #endif
267 /* At some point during the gcc 2.8 development the `format_arg' attribute
268 for functions was introduced. We don't want to use it unconditionally
269 (although this would be possible) since it generates warnings.
270 If several `format_arg' attributes are given for the same function, in
271 gcc-3.0 and older, all but the last one are ignored. In newer gccs,
272 all designated arguments are considered. */
273 #if __GNUC_PREREQ (2,8)
274 # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
275 #else
276 # define __attribute_format_arg__(x) /* Ignore */
277 #endif
279 /* At some point during the gcc 2.97 development the `strfmon' format
280 attribute for functions was introduced. We don't want to use it
281 unconditionally (although this would be possible) since it
282 generates warnings. */
283 #if __GNUC_PREREQ (2,97)
284 # define __attribute_format_strfmon__(a,b) \
285 __attribute__ ((__format__ (__strfmon__, a, b)))
286 #else
287 # define __attribute_format_strfmon__(a,b) /* Ignore */
288 #endif
290 /* The nonull function attribute allows to mark pointer parameters which
291 must not be NULL. */
292 #if __GNUC_PREREQ (3,3)
293 # define __nonnull(params) __attribute__ ((__nonnull__ params))
294 #else
295 # define __nonnull(params)
296 #endif
298 /* If fortification mode, we warn about unused results of certain
299 function calls which can lead to problems. */
300 #if __GNUC_PREREQ (3,4)
301 # define __attribute_warn_unused_result__ \
302 __attribute__ ((__warn_unused_result__))
303 # if __USE_FORTIFY_LEVEL > 0
304 # define __wur __attribute_warn_unused_result__
305 # endif
306 #else
307 # define __attribute_warn_unused_result__ /* empty */
308 #endif
309 #ifndef __wur
310 # define __wur /* Ignore */
311 #endif
313 /* Forces a function to be always inlined. */
314 #if __GNUC_PREREQ (3,2)
315 # define __always_inline __inline __attribute__ ((__always_inline__))
316 #else
317 # define __always_inline __inline
318 #endif
320 /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
321 inline semantics, unless -fgnu89-inline is used.
322 For -std=gnu99, forcing gnu_inline attribute does not change behavior,
323 but may silence spurious warnings (such as in GCC 4.2). */
324 #if !defined __cplusplus || __GNUC_PREREQ (4,3)
325 # if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ || defined __cplusplus
326 # define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
327 # if __GNUC_PREREQ (4,3)
328 # define __extern_always_inline \
329 extern __always_inline __attribute__ ((__gnu_inline__, __artificial__))
330 # else
331 # define __extern_always_inline \
332 extern __always_inline __attribute__ ((__gnu_inline__))
333 # endif
334 # else
335 # define __extern_inline extern __inline
336 # define __extern_always_inline extern __always_inline
337 # endif
338 #endif
340 /* GCC 4.3 and above allow passing all anonymous arguments of an
341 __extern_always_inline function to some other vararg function. */
342 #if __GNUC_PREREQ (4,3)
343 # define __va_arg_pack() __builtin_va_arg_pack ()
344 # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
345 #endif
347 /* It is possible to compile containing GCC extensions even if GCC is
348 run in pedantic mode if the uses are carefully marked using the
349 `__extension__' keyword. But this is not generally available before
350 version 2.8. */
351 #if !__GNUC_PREREQ (2,8)
352 # define __extension__ /* Ignore */
353 #endif
355 /* __restrict is known in EGCS 1.2 and above. */
356 #if !__GNUC_PREREQ (2,92)
357 # define __restrict /* Ignore */
358 #endif
360 /* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
361 array_name[restrict]
362 GCC 3.1 supports this. */
363 #if __GNUC_PREREQ (3,1) && !defined __GNUG__
364 # define __restrict_arr __restrict
365 #else
366 # ifdef __GNUC__
367 # define __restrict_arr /* Not supported in old GCC. */
368 # else
369 # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
370 # define __restrict_arr restrict
371 # else
372 /* Some other non-C99 compiler. */
373 # define __restrict_arr /* Not supported. */
374 # endif
375 # endif
376 #endif
378 #endif /* sys/cdefs.h */