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.
4 
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.
9 
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.
14 
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/>.  */
18 
19 #ifndef	_SYS_CDEFS_H
20 #define	_SYS_CDEFS_H	1
21 
22 /* We are almost always included from features.h. */
23 #ifndef _FEATURES_H
24 # include <features.h>
25 #endif
26 
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
33 
34 /* Some user header file might have defined this before.  */
35 #undef	__P
36 #undef	__PMT
37 
38 #ifdef __GNUC__
39 
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
49 
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 /* Dynamic exception specification is deprecated since C++11, so
62    we only use it when compiling for an earlier standard.  */
63 #   if __cplusplus < 201103UL
64 #    define __THROW	throw ()
65 #   else
66 #    define __THROW	noexcept
67 #   endif
68 #   define __THROWNL	__THROW
69 #   define __NTH(fct)	__LEAF_ATTR fct __THROW
70 #  else
71 #   define __THROW
72 #   define __THROWNL
73 #   define __NTH(fct)	fct
74 #  endif
75 # endif
76 
77 #else	/* Not GCC.  */
78 
79 # define __inline		/* No inline functions.  */
80 
81 # define __THROW
82 # define __THROWNL
83 # define __NTH(fct)	fct
84 
85 #endif	/* GCC.  */
86 
87 /* These two macros are not used in glibc anymore.  They are kept here
88    only because some other projects expect the macros to be defined.  */
89 #define __P(args)	args
90 #define __PMT(args)	args
91 
92 /* For these things, GCC behaves the ANSI way normally,
93    and the non-ANSI way under -traditional.  */
94 
95 #define __CONCAT(x,y)	x ## y
96 #define __STRING(x)	#x
97 
98 /* This is not a typedef so `const __ptr_t' does the right thing.  */
99 #define __ptr_t void *
100 #define __long_double_t  long double
101 
102 
103 /* C++ needs to know that types and declarations are C, not C++.  */
104 #ifdef	__cplusplus
105 # define __BEGIN_DECLS	extern "C" {
106 # define __END_DECLS	}
107 #else
108 # define __BEGIN_DECLS
109 # define __END_DECLS
110 #endif
111 
112 
113 /* The standard library needs the functions from the ISO C90 standard
114    in the std namespace.  At the same time we want to be safe for
115    future changes and we include the ISO C99 code in the non-standard
116    namespace __c99.  The C++ wrapper header take case of adding the
117    definitions to the global namespace.  */
118 #if defined __cplusplus && defined _GLIBCPP_USE_NAMESPACES
119 # define __BEGIN_NAMESPACE_STD	namespace std {
120 # define __END_NAMESPACE_STD	}
121 # define __USING_NAMESPACE_STD(name) using std::name;
122 # define __BEGIN_NAMESPACE_C99	namespace __c99 {
123 # define __END_NAMESPACE_C99	}
124 # define __USING_NAMESPACE_C99(name) using __c99::name;
125 #else
126 /* For compatibility we do not add the declarations into any
127    namespace.  They will end up in the global namespace which is what
128    old code expects.  */
129 # define __BEGIN_NAMESPACE_STD
130 # define __END_NAMESPACE_STD
131 # define __USING_NAMESPACE_STD(name)
132 # define __BEGIN_NAMESPACE_C99
133 # define __END_NAMESPACE_C99
134 # define __USING_NAMESPACE_C99(name)
135 #endif
136 
137 
138 #if __GNUC_PREREQ (4,3)
139 # define __warndecl(name, msg) \
140   extern void name (void) __attribute__((__warning__ (msg)))
141 # define __warnattr(msg) __attribute__((__warning__ (msg)))
142 # define __errordecl(name, msg) \
143   extern void name (void) __attribute__((__error__ (msg)))
144 #else
145 # define __warndecl(name, msg) extern void name (void)
146 # define __warnattr(msg)
147 # define __errordecl(name, msg) extern void name (void)
148 #endif
149 
150 /* Support for flexible arrays.  */
151 #if __GNUC_PREREQ (2,97)
152 /* GCC 2.97 supports C99 flexible array members.  */
153 # define __flexarr	[]
154 #else
155 # ifdef __GNUC__
156 #  define __flexarr	[0]
157 # else
158 #  if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
159 #   define __flexarr	[]
160 #  else
161 /* Some other non-C99 compiler.  Approximate with [1].  */
162 #   define __flexarr	[1]
163 #  endif
164 # endif
165 #endif
166 
167 
168 /* __asm__ ("xyz") is used throughout the headers to rename functions
169    at the assembly language level.  This is wrapped by the __REDIRECT
170    macro, in order to support compilers that can do this some other
171    way.  When compilers don't support asm-names at all, we have to do
172    preprocessor tricks instead (which don't have exactly the right
173    semantics, but it's the best we can do).
174 
175    Example:
176    int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
177 
178 #if defined __GNUC__ && __GNUC__ >= 2
179 
180 # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
181 # ifdef __cplusplus
182 #  define __REDIRECT_NTH(name, proto, alias) \
183      name proto __THROW __asm__ (__ASMNAME (#alias))
184 #  define __REDIRECT_NTHNL(name, proto, alias) \
185      name proto __THROWNL __asm__ (__ASMNAME (#alias))
186 # else
187 #  define __REDIRECT_NTH(name, proto, alias) \
188      name proto __asm__ (__ASMNAME (#alias)) __THROW
189 #  define __REDIRECT_NTHNL(name, proto, alias) \
190      name proto __asm__ (__ASMNAME (#alias)) __THROWNL
191 # endif
192 # define __ASMNAME(cname)  __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
193 # define __ASMNAME2(prefix, cname) __STRING (prefix) cname
194 
195 /*
196 #elif __SOME_OTHER_COMPILER__
197 
198 # define __REDIRECT(name, proto, alias) name proto; \
199 	_Pragma("let " #name " = " #alias)
200 */
201 #endif
202 
203 /* GCC has various useful declarations that can be made with the
204    `__attribute__' syntax.  All of the ways we use this do fine if
205    they are omitted for compilers that don't understand it. */
206 #if !defined __GNUC__ || __GNUC__ < 2
207 # define __attribute__(xyz)	/* Ignore */
208 #endif
209 
210 /* We make this a no-op unless it can be used as both a variable and
211    a type attribute.  gcc 2.8 is known to support both.  */
212 #if __GNUC_PREREQ (2,8)
213 # define __attribute_aligned__(size) __attribute__ ((__aligned__ (size)))
214 #else
215 # define __attribute_aligned__(size) /* Ignore */
216 #endif
217 
218 /* At some point during the gcc 2.96 development the `malloc' attribute
219    for functions was introduced.  We don't want to use it unconditionally
220    (although this would be possible) since it generates warnings.  */
221 #if __GNUC_PREREQ (2,96)
222 # define __attribute_malloc__ __attribute__ ((__malloc__))
223 #else
224 # define __attribute_malloc__ /* Ignore */
225 #endif
226 
227 /* Tell the compiler which arguments to an allocation function
228    indicate the size of the allocation.  */
229 #if __GNUC_PREREQ (4, 3)
230 # define __attribute_alloc_size__(params) \
231   __attribute__ ((__alloc_size__ params))
232 #else
233 # define __attribute_alloc_size__(params) /* Ignore.  */
234 #endif
235 
236 /* At some point during the gcc 2.96 development the `pure' attribute
237    for functions was introduced.  We don't want to use it unconditionally
238    (although this would be possible) since it generates warnings.  */
239 #if __GNUC_PREREQ (2,96)
240 # define __attribute_pure__ __attribute__ ((__pure__))
241 #else
242 # define __attribute_pure__ /* Ignore */
243 #endif
244 
245 #if __GNUC_PREREQ (2,96)
246 # define __attribute_const__ __attribute__((__const__))
247 #else
248 # define __attribute_const__     /* unimplemented */
249 #endif
250 
251 /* At some point during the gcc 3.1 development the `used' attribute
252    for functions was introduced.  We don't want to use it unconditionally
253    (although this would be possible) since it generates warnings.  */
254 #if __GNUC_PREREQ (3,1)
255 # define __attribute_used__ __attribute__ ((__used__))
256 # define __attribute_noinline__ __attribute__ ((__noinline__))
257 #else
258 # define __attribute_used__ __attribute__ ((__unused__))
259 # define __attribute_noinline__ /* Ignore */
260 #endif
261 
262 /* gcc allows marking deprecated functions.  */
263 #if __GNUC_PREREQ (3,2) && !defined(__UCLIBC_HIDE_DEPRECATED__)
264 # define __attribute_deprecated__ __attribute__ ((__deprecated__))
265 #else
266 # define __attribute_deprecated__ /* Ignore */
267 #endif
268 
269 /* At some point during the gcc 2.8 development the `format_arg' attribute
270    for functions was introduced.  We don't want to use it unconditionally
271    (although this would be possible) since it generates warnings.
272    If several `format_arg' attributes are given for the same function, in
273    gcc-3.0 and older, all but the last one are ignored.  In newer gccs,
274    all designated arguments are considered.  */
275 #if __GNUC_PREREQ (2,8)
276 # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
277 #else
278 # define __attribute_format_arg__(x) /* Ignore */
279 #endif
280 
281 /* At some point during the gcc 2.97 development the `strfmon' format
282    attribute for functions was introduced.  We don't want to use it
283    unconditionally (although this would be possible) since it
284    generates warnings.  */
285 #if __GNUC_PREREQ (2,97)
286 # define __attribute_format_strfmon__(a,b) \
287   __attribute__ ((__format__ (__strfmon__, a, b)))
288 #else
289 # define __attribute_format_strfmon__(a,b) /* Ignore */
290 #endif
291 
292 /* The nonull function attribute allows to mark pointer parameters which
293    must not be NULL.  */
294 #if __GNUC_PREREQ (3,3)
295 # define __nonnull(params) __attribute__ ((__nonnull__ params))
296 #else
297 # define __nonnull(params)
298 #endif
299 
300 /* If fortification mode, we warn about unused results of certain
301    function calls which can lead to problems.  */
302 #if __GNUC_PREREQ (3,4)
303 # define __attribute_warn_unused_result__ \
304    __attribute__ ((__warn_unused_result__))
305 #else
306 # define __attribute_warn_unused_result__ /* empty */
307 #endif
308 #ifndef __wur
309 # define __wur /* Ignore */
310 #endif
311 
312 /* Forces a function to be always inlined.  */
313 #if __GNUC_PREREQ (3,2)
314 # define __always_inline __inline __attribute__ ((__always_inline__))
315 #else
316 # define __always_inline __inline
317 #endif
318 
319 /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
320    inline semantics, unless -fgnu89-inline is used.
321    For -std=gnu99, forcing gnu_inline attribute does not change behavior,
322    but may silence spurious warnings (such as in GCC 4.2).  */
323 #if !defined __cplusplus || __GNUC_PREREQ (4,3) || __CLANG_PREREQ(8,0)
324 # if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ || defined __cplusplus
325 #  define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
326 #  if __GNUC_PREREQ (4,3)
327 #   define __extern_always_inline \
328   extern __always_inline __attribute__ ((__gnu_inline__, __artificial__))
329 #  else
330 #   define __extern_always_inline \
331   extern __always_inline __attribute__ ((__gnu_inline__))
332 #  endif
333 # else
334 #  define __extern_inline extern __inline
335 #  define __extern_always_inline extern __always_inline
336 # endif
337 #endif
338 
339 /* Undefine (also defined in libc-symbols.h).  */
340 #undef __attribute_copy__
341 #if __GNUC_PREREQ (9, 0)
342 /* Copies attributes from the declaration or type referenced by
343    the argument.  */
344 # define __attribute_copy__(arg) __attribute__ ((__copy__ (arg)))
345 #else
346 # define __attribute_copy__(arg)
347 #endif
348 
349 
350 /* GCC 4.3 and above allow passing all anonymous arguments of an
351    __extern_always_inline function to some other vararg function.  */
352 #if __GNUC_PREREQ (4,3)
353 # define __va_arg_pack() __builtin_va_arg_pack ()
354 # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
355 #endif
356 
357 /* It is possible to compile containing GCC extensions even if GCC is
358    run in pedantic mode if the uses are carefully marked using the
359    `__extension__' keyword.  But this is not generally available before
360    version 2.8.  */
361 #if !__GNUC_PREREQ (2,8)
362 # define __extension__		/* Ignore */
363 #endif
364 
365 /* __restrict is known in EGCS 1.2 and above. */
366 #if !__GNUC_PREREQ (2,92)
367 # define __restrict	/* Ignore */
368 #endif
369 
370 /* ISO C99 also allows to declare arrays as non-overlapping.  The syntax is
371      array_name[restrict]
372    GCC 3.1 supports this.  */
373 #if __GNUC_PREREQ (3,1) && !defined __GNUG__
374 # define __restrict_arr	__restrict
375 #else
376 # ifdef __GNUC__
377 #  define __restrict_arr	/* Not supported in old GCC.  */
378 # else
379 #  if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
380 #   define __restrict_arr	restrict
381 #  else
382 /* Some other non-C99 compiler.  */
383 #   define __restrict_arr	/* Not supported.  */
384 #  endif
385 # endif
386 #endif
387 
388 #endif	 /* sys/cdefs.h */
389