Subversion Repositories Kolibri OS

Rev

Rev 5191 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5191 Rev 6324
Line 1... Line 1...
1
/* ANSI and traditional C compatability macros
1
/* ANSI and traditional C compatability macros
2
   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-
 
3
   2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010
-
 
4
   Free Software Foundation, Inc.
2
   Copyright (C) 1991-2015 Free Software Foundation, Inc.
5
   This file is part of the GNU C Library.
3
   This file is part of the GNU C Library.
Line 6... Line 4...
6
 
4
 
7
This program is free software; you can redistribute it and/or modify
5
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
6
it under the terms of the GNU General Public License as published by
Line 22... Line 20...
22
 
20
 
Line 23... Line 21...
23
   ANSI C is assumed if __STDC__ is #defined.
21
   ANSI C is assumed if __STDC__ is #defined.
24
 
22
 
25
   Macro		ANSI C definition	Traditional C definition
-
 
26
   -----		---- - ----------	----------- - ----------
23
   Macro		ANSI C definition	Traditional C definition
27
   ANSI_PROTOTYPES	1			not defined
-
 
28
   PTR			`void *'		`char *'
-
 
29
   PTRCONST		`void *const'		`char *'
24
   -----		---- - ----------	----------- - ----------
30
   LONG_DOUBLE		`long double'		`double'
25
   PTR			`void *'		`char *'
31
   const		not defined		`'
26
   const		not defined		`'
32
   volatile		not defined		`'
-
 
33
   signed		not defined		`'
-
 
34
   VA_START(ap, var)	va_start(ap, var)	va_start(ap)
-
 
35
 
-
 
36
   Note that it is safe to write "void foo();" indicating a function
-
 
37
   with no return value, in all K+R compilers we have been able to test.
-
 
38
 
-
 
39
   For declaring functions with prototypes, we also provide these:
-
 
40
 
-
 
41
   PARAMS ((prototype))
-
 
42
   -- for functions which take a fixed number of arguments.  Use this
-
 
43
   when declaring the function.  When defining the function, write a
-
 
44
   K+R style argument list.  For example:
-
 
45
 
-
 
46
	char *strcpy PARAMS ((char *dest, char *source));
-
 
47
	...
-
 
48
	char *
-
 
49
	strcpy (dest, source)
-
 
50
	     char *dest;
-
 
51
	     char *source;
-
 
52
	{ ... }
-
 
53
 
-
 
54
 
-
 
55
   VPARAMS ((prototype, ...))
-
 
56
   -- for functions which take a variable number of arguments.  Use
-
 
57
   PARAMS to declare the function, VPARAMS to define it.  For example:
-
 
58
 
-
 
59
	int printf PARAMS ((const char *format, ...));
-
 
60
	...
-
 
61
	int
-
 
62
	printf VPARAMS ((const char *format, ...))
-
 
63
	{
-
 
64
	   ...
-
 
65
	}
-
 
66
 
-
 
67
   For writing functions which take variable numbers of arguments, we
-
 
68
   also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros.  These
-
 
69
   hide the differences between K+R  and C89  more
-
 
70
   thoroughly than the simple VA_START() macro mentioned above.
-
 
71
 
-
 
72
   VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end.
-
 
73
   Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls
-
 
74
   corresponding to the list of fixed arguments.  Then use va_arg
-
 
75
   normally to get the variable arguments, or pass your va_list object
-
 
76
   around.  You do not declare the va_list yourself; VA_OPEN does it
-
 
77
   for you.
-
 
78
 
-
 
79
   Here is a complete example:
-
 
80
 
-
 
81
	int
-
 
82
	printf VPARAMS ((const char *format, ...))
-
 
83
	{
-
 
84
	   int result;
-
 
85
 
-
 
86
	   VA_OPEN (ap, format);
-
 
87
	   VA_FIXEDARG (ap, const char *, format);
-
 
88
 
-
 
89
	   result = vfprintf (stdout, format, ap);
-
 
90
	   VA_CLOSE (ap);
-
 
91
 
-
 
92
	   return result;
-
 
93
	}
-
 
94
 
-
 
95
 
-
 
96
   You can declare variables either before or after the VA_OPEN,
-
 
97
   VA_FIXEDARG sequence.  Also, VA_OPEN and VA_CLOSE are the beginning
-
 
98
   and end of a block.  They must appear at the same nesting level,
-
 
99
   and any variables declared after VA_OPEN go out of scope at
-
 
100
   VA_CLOSE.  Unfortunately, with a K+R compiler, that includes the
-
 
101
   argument list.  You can have multiple instances of VA_OPEN/VA_CLOSE
-
 
Line 102... Line 27...
102
   pairs in a single function in case you need to traverse the
27
   volatile		not defined		`'
103
   argument list more than once.
28
   signed		not defined		`'
104
 
29
 
105
   For ease of writing code which uses GCC extensions but needs to be
30
   For ease of writing code which uses GCC extensions but needs to be
106
   portable to other compilers, we provide the GCC_VERSION macro that
31
   portable to other compilers, we provide the GCC_VERSION macro that
107
   simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
-
 
108
   wrappers around __attribute__.  Also, __extension__ will be #defined
-
 
109
   to nothing if it doesn't work.  See below.
-
 
110
 
-
 
Line 111... Line 32...
111
   This header also defines a lot of obsolete macros:
32
   simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
112
   CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID,
33
   wrappers around __attribute__.  Also, __extension__ will be #defined
Line 113... Line 34...
113
   AND, DOTS, NOARGS.  Don't use them.  */
34
   to nothing if it doesn't work.  See below.  */
Line 147... Line 68...
147
   in SVR4 mode, but does not define __STDC__.  */
68
   in SVR4 mode, but does not define __STDC__.  */
148
/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
69
/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
149
   C++ compilers, does not define __STDC__, though it acts as if this
70
   C++ compilers, does not define __STDC__, though it acts as if this
150
   was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
71
   was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
Line 151... Line -...
151
 
-
 
152
#define ANSI_PROTOTYPES	1
72
 
153
#define PTR		void *
-
 
154
#define PTRCONST	void *const
-
 
155
#define LONG_DOUBLE	long double
-
 
156
 
-
 
157
/* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in
-
 
158
   a #ifndef.  */
-
 
159
#ifndef PARAMS
-
 
160
#define PARAMS(ARGS)		ARGS
-
 
161
#endif
-
 
162
 
-
 
163
#define VPARAMS(ARGS)		ARGS
-
 
164
#define VA_START(VA_LIST, VAR)	va_start(VA_LIST, VAR)
-
 
165
 
-
 
166
/* variadic function helper macros */
-
 
167
/* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's
-
 
168
   use without inhibiting further decls and without declaring an
-
 
169
   actual variable.  */
-
 
170
#define VA_OPEN(AP, VAR)	{ va_list AP; va_start(AP, VAR); { struct Qdmy
-
 
171
#define VA_CLOSE(AP)		} va_end(AP); }
-
 
Line 172... Line 73...
172
#define VA_FIXEDARG(AP, T, N)	struct Qdmy
73
#define PTR		void *
173
 
74
 
174
#undef const
75
#undef const
Line 186... Line 87...
186
# else
87
# else
187
#  define inline  /* nothing */
88
#  define inline  /* nothing */
188
# endif
89
# endif
189
#endif
90
#endif
Line 190... Line -...
190
 
-
 
191
/* These are obsolete.  Do not use.  */
-
 
192
#ifndef IN_GCC
-
 
193
#define CONST		const
-
 
194
#define VOLATILE	volatile
-
 
195
#define SIGNED		signed
-
 
196
 
-
 
197
#define PROTO(type, name, arglist)	type name arglist
-
 
198
#define EXFUN(name, proto)		name proto
-
 
199
#define DEFUN(name, arglist, args)	name(args)
-
 
200
#define DEFUN_VOID(name)		name(void)
-
 
201
#define AND		,
-
 
202
#define DOTS		, ...
-
 
203
#define NOARGS		void
-
 
204
#endif /* ! IN_GCC */
-
 
205
 
91
 
Line 206... Line -...
206
#else	/* Not ANSI C.  */
-
 
207
 
92
#else	/* Not ANSI C.  */
208
#undef  ANSI_PROTOTYPES
-
 
209
#define PTR		char *
-
 
210
#define PTRCONST	PTR
-
 
211
#define LONG_DOUBLE	double
-
 
212
 
-
 
213
#define PARAMS(args)		()
-
 
214
#define VPARAMS(args)		(va_alist) va_dcl
-
 
215
#define VA_START(va_list, var)	va_start(va_list)
-
 
216
 
-
 
217
#define VA_OPEN(AP, VAR)		{ va_list AP; va_start(AP); { struct Qdmy
-
 
Line 218... Line 93...
218
#define VA_CLOSE(AP)			} va_end(AP); }
93
 
219
#define VA_FIXEDARG(AP, TYPE, NAME)	TYPE NAME = va_arg(AP, TYPE)
94
#define PTR		char *
220
 
95
 
221
/* some systems define these in header files for non-ansi mode */
96
/* some systems define these in header files for non-ansi mode */
Line 226... Line 101...
226
#define const
101
#define const
227
#define volatile
102
#define volatile
228
#define signed
103
#define signed
229
#define inline
104
#define inline
Line 230... Line -...
230
 
-
 
231
#ifndef IN_GCC
-
 
232
#define CONST
-
 
233
#define VOLATILE
-
 
234
#define SIGNED
-
 
235
 
-
 
236
#define PROTO(type, name, arglist)	type name ()
-
 
237
#define EXFUN(name, proto)		name()
-
 
238
#define DEFUN(name, arglist, args)	name arglist args;
-
 
239
#define DEFUN_VOID(name)		name()
-
 
240
#define AND		;
-
 
241
#define DOTS
-
 
242
#define NOARGS
-
 
243
#endif /* ! IN_GCC */
-
 
244
 
105
 
Line 245... Line 106...
245
#endif	/* ANSI C.  */
106
#endif	/* ANSI C.  */
246
 
107
 
247
/* Define macros for some gcc attributes.  This permits us to use the
108
/* Define macros for some gcc attributes.  This permits us to use the
Line 309... Line 170...
309
# else
170
# else
310
#  define ATTRIBUTE_NONNULL(m)
171
#  define ATTRIBUTE_NONNULL(m)
311
# endif /* GNUC >= 3.3 */
172
# endif /* GNUC >= 3.3 */
312
#endif /* ATTRIBUTE_NONNULL */
173
#endif /* ATTRIBUTE_NONNULL */
Line -... Line 174...
-
 
174
 
-
 
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 */
313
 
183
 
314
/* Attribute `pure' was valid as of gcc 3.0.  */
184
/* Attribute `pure' was valid as of gcc 3.0.  */
315
#ifndef ATTRIBUTE_PURE
185
#ifndef ATTRIBUTE_PURE
316
# if (GCC_VERSION >= 3000)
186
# if (GCC_VERSION >= 3000)
317
#  define ATTRIBUTE_PURE __attribute__ ((__pure__))
187
#  define ATTRIBUTE_PURE __attribute__ ((__pure__))
Line 402... Line 272...
402
# else
272
# else
403
#  define ATTRIBUTE_HOT
273
#  define ATTRIBUTE_HOT
404
# endif /* GNUC >= 4.3 */
274
# endif /* GNUC >= 4.3 */
405
#endif /* ATTRIBUTE_HOT */
275
#endif /* ATTRIBUTE_HOT */
Line -... Line 276...
-
 
276
 
-
 
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 */
406
 
285
 
407
/* We use __extension__ in some places to suppress -pedantic warnings
286
/* We use __extension__ in some places to suppress -pedantic warnings
408
   about GCC extensions.  This feature didn't work properly before
287
   about GCC extensions.  This feature didn't work properly before
409
   gcc 2.8.  */
288
   gcc 2.8.  */
410
#if GCC_VERSION < 2008
289
#if GCC_VERSION < 2008
Line 432... Line 311...
432
#define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
311
#define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
433
#else
312
#else
434
#define ENUM_BITFIELD(TYPE) unsigned int
313
#define ENUM_BITFIELD(TYPE) unsigned int
435
#endif
314
#endif
Line -... Line 315...
-
 
315
 
-
 
316
    /* This is used to mark a class or virtual function as final.  */
-
 
317
#if __cplusplus >= 201103L
-
 
318
#define GCC_FINAL final
-
 
319
#elif GCC_VERSION >= 4007
-
 
320
#define GCC_FINAL __final
-
 
321
#else
-
 
322
#define GCC_FINAL
-
 
323
#endif
436
 
324
 
437
#ifdef __cplusplus
325
#ifdef __cplusplus
438
}
326
}
Line 439... Line 327...
439
#endif
327
#endif