Search
lxdream.org :: lxdream/src/xlat/disasm/ansidecl.h
lxdream 0.9.1
released Jun 29
Download Now
filename src/xlat/disasm/ansidecl.h
changeset 1264:74ad81710528
prevsrc/x86dasm/ansidecl.h@362:dc40e2064dc4
author nkeynes
date Tue Mar 06 12:19:08 2012 +1000 (8 years ago)
permissions -rw-r--r--
last change Move x86dasm/* files under xlat/disasm
file annotate diff log raw
nkeynes@362
     1
/* ANSI and traditional C compatability macros
nkeynes@362
     2
   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
nkeynes@362
     3
   Free Software Foundation, Inc.
nkeynes@362
     4
   This file is part of the GNU C Library.
nkeynes@362
     5
nkeynes@362
     6
This program is free software; you can redistribute it and/or modify
nkeynes@362
     7
it under the terms of the GNU General Public License as published by
nkeynes@362
     8
the Free Software Foundation; either version 2 of the License, or
nkeynes@362
     9
(at your option) any later version.
nkeynes@362
    10
nkeynes@362
    11
This program is distributed in the hope that it will be useful,
nkeynes@362
    12
but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@362
    13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@362
    14
GNU General Public License for more details.
nkeynes@362
    15
nkeynes@362
    16
You should have received a copy of the GNU General Public License
nkeynes@362
    17
along with this program; if not, write to the Free Software
nkeynes@362
    18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
nkeynes@362
    19
nkeynes@362
    20
/* ANSI and traditional C compatibility macros
nkeynes@362
    21
nkeynes@362
    22
   ANSI C is assumed if __STDC__ is #defined.
nkeynes@362
    23
nkeynes@362
    24
   Macro		ANSI C definition	Traditional C definition
nkeynes@362
    25
   -----		---- - ----------	----------- - ----------
nkeynes@362
    26
   ANSI_PROTOTYPES	1			not defined
nkeynes@362
    27
   PTR			`void *'		`char *'
nkeynes@362
    28
   PTRCONST		`void *const'		`char *'
nkeynes@362
    29
   LONG_DOUBLE		`long double'		`double'
nkeynes@362
    30
   const		not defined		`'
nkeynes@362
    31
   volatile		not defined		`'
nkeynes@362
    32
   signed		not defined		`'
nkeynes@362
    33
   VA_START(ap, var)	va_start(ap, var)	va_start(ap)
nkeynes@362
    34
nkeynes@362
    35
   Note that it is safe to write "void foo();" indicating a function
nkeynes@362
    36
   with no return value, in all K+R compilers we have been able to test.
nkeynes@362
    37
nkeynes@362
    38
   For declaring functions with prototypes, we also provide these:
nkeynes@362
    39
nkeynes@362
    40
   PARAMS ((prototype))
nkeynes@362
    41
   -- for functions which take a fixed number of arguments.  Use this
nkeynes@362
    42
   when declaring the function.  When defining the function, write a
nkeynes@362
    43
   K+R style argument list.  For example:
nkeynes@362
    44
nkeynes@362
    45
	char *strcpy PARAMS ((char *dest, char *source));
nkeynes@362
    46
	...
nkeynes@362
    47
	char *
nkeynes@362
    48
	strcpy (dest, source)
nkeynes@362
    49
	     char *dest;
nkeynes@362
    50
	     char *source;
nkeynes@362
    51
	{ ... }
nkeynes@362
    52
nkeynes@362
    53
nkeynes@362
    54
   VPARAMS ((prototype, ...))
nkeynes@362
    55
   -- for functions which take a variable number of arguments.  Use
nkeynes@362
    56
   PARAMS to declare the function, VPARAMS to define it.  For example:
nkeynes@362
    57
nkeynes@362
    58
	int printf PARAMS ((const char *format, ...));
nkeynes@362
    59
	...
nkeynes@362
    60
	int
nkeynes@362
    61
	printf VPARAMS ((const char *format, ...))
nkeynes@362
    62
	{
nkeynes@362
    63
	   ...
nkeynes@362
    64
	}
nkeynes@362
    65
nkeynes@362
    66
   For writing functions which take variable numbers of arguments, we
nkeynes@362
    67
   also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros.  These
nkeynes@362
    68
   hide the differences between K+R <varargs.h> and C89 <stdarg.h> more
nkeynes@362
    69
   thoroughly than the simple VA_START() macro mentioned above.
nkeynes@362
    70
nkeynes@362
    71
   VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end.
nkeynes@362
    72
   Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls
nkeynes@362
    73
   corresponding to the list of fixed arguments.  Then use va_arg
nkeynes@362
    74
   normally to get the variable arguments, or pass your va_list object
nkeynes@362
    75
   around.  You do not declare the va_list yourself; VA_OPEN does it
nkeynes@362
    76
   for you.
nkeynes@362
    77
nkeynes@362
    78
   Here is a complete example:
nkeynes@362
    79
nkeynes@362
    80
	int
nkeynes@362
    81
	printf VPARAMS ((const char *format, ...))
nkeynes@362
    82
	{
nkeynes@362
    83
	   int result;
nkeynes@362
    84
nkeynes@362
    85
	   VA_OPEN (ap, format);
nkeynes@362
    86
	   VA_FIXEDARG (ap, const char *, format);
nkeynes@362
    87
nkeynes@362
    88
	   result = vfprintf (stdout, format, ap);
nkeynes@362
    89
	   VA_CLOSE (ap);
nkeynes@362
    90
nkeynes@362
    91
	   return result;
nkeynes@362
    92
	}
nkeynes@362
    93
nkeynes@362
    94
nkeynes@362
    95
   You can declare variables either before or after the VA_OPEN,
nkeynes@362
    96
   VA_FIXEDARG sequence.  Also, VA_OPEN and VA_CLOSE are the beginning
nkeynes@362
    97
   and end of a block.  They must appear at the same nesting level,
nkeynes@362
    98
   and any variables declared after VA_OPEN go out of scope at
nkeynes@362
    99
   VA_CLOSE.  Unfortunately, with a K+R compiler, that includes the
nkeynes@362
   100
   argument list.  You can have multiple instances of VA_OPEN/VA_CLOSE
nkeynes@362
   101
   pairs in a single function in case you need to traverse the
nkeynes@362
   102
   argument list more than once.
nkeynes@362
   103
nkeynes@362
   104
   For ease of writing code which uses GCC extensions but needs to be
nkeynes@362
   105
   portable to other compilers, we provide the GCC_VERSION macro that
nkeynes@362
   106
   simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
nkeynes@362
   107
   wrappers around __attribute__.  Also, __extension__ will be #defined
nkeynes@362
   108
   to nothing if it doesn't work.  See below.
nkeynes@362
   109
nkeynes@362
   110
   This header also defines a lot of obsolete macros:
nkeynes@362
   111
   CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID,
nkeynes@362
   112
   AND, DOTS, NOARGS.  Don't use them.  */
nkeynes@362
   113
nkeynes@362
   114
#ifndef	_ANSIDECL_H
nkeynes@362
   115
#define _ANSIDECL_H	1
nkeynes@362
   116
nkeynes@362
   117
/* Every source file includes this file,
nkeynes@362
   118
   so they will all get the switch for lint.  */
nkeynes@362
   119
/* LINTLIBRARY */
nkeynes@362
   120
nkeynes@362
   121
/* Using MACRO(x,y) in cpp #if conditionals does not work with some
nkeynes@362
   122
   older preprocessors.  Thus we can't define something like this:
nkeynes@362
   123
nkeynes@362
   124
#define HAVE_GCC_VERSION(MAJOR, MINOR) \
nkeynes@362
   125
  (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
nkeynes@362
   126
nkeynes@362
   127
and then test "#if HAVE_GCC_VERSION(2,7)".
nkeynes@362
   128
nkeynes@362
   129
So instead we use the macro below and test it against specific values.  */
nkeynes@362
   130
nkeynes@362
   131
/* This macro simplifies testing whether we are using gcc, and if it
nkeynes@362
   132
   is of a particular minimum version. (Both major & minor numbers are
nkeynes@362
   133
   significant.)  This macro will evaluate to 0 if we are not using
nkeynes@362
   134
   gcc at all.  */
nkeynes@362
   135
#ifndef GCC_VERSION
nkeynes@362
   136
#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
nkeynes@362
   137
#endif /* GCC_VERSION */
nkeynes@362
   138
nkeynes@362
   139
#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) || (defined(__alpha) && defined(__cplusplus))
nkeynes@362
   140
/* All known AIX compilers implement these things (but don't always
nkeynes@362
   141
   define __STDC__).  The RISC/OS MIPS compiler defines these things
nkeynes@362
   142
   in SVR4 mode, but does not define __STDC__.  */
nkeynes@362
   143
/* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
nkeynes@362
   144
   C++ compilers, does not define __STDC__, though it acts as if this
nkeynes@362
   145
   was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
nkeynes@362
   146
nkeynes@362
   147
#define ANSI_PROTOTYPES	1
nkeynes@362
   148
#define PTR		void *
nkeynes@362
   149
#define PTRCONST	void *const
nkeynes@362
   150
#define LONG_DOUBLE	long double
nkeynes@362
   151
nkeynes@362
   152
/* PARAMS is often defined elsewhere (e.g. by libintl.h), so wrap it in
nkeynes@362
   153
   a #ifndef.  */
nkeynes@362
   154
#ifndef PARAMS
nkeynes@362
   155
#define PARAMS(ARGS)		ARGS
nkeynes@362
   156
#endif
nkeynes@362
   157
nkeynes@362
   158
#define VPARAMS(ARGS)		ARGS
nkeynes@362
   159
#define VA_START(VA_LIST, VAR)	va_start(VA_LIST, VAR)
nkeynes@362
   160
nkeynes@362
   161
/* variadic function helper macros */
nkeynes@362
   162
/* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's
nkeynes@362
   163
   use without inhibiting further decls and without declaring an
nkeynes@362
   164
   actual variable.  */
nkeynes@362
   165
#define VA_OPEN(AP, VAR)	{ va_list AP; va_start(AP, VAR); { struct Qdmy
nkeynes@362
   166
#define VA_CLOSE(AP)		} va_end(AP); }
nkeynes@362
   167
#define VA_FIXEDARG(AP, T, N)	struct Qdmy
nkeynes@362
   168
 
nkeynes@362
   169
#undef const
nkeynes@362
   170
#undef volatile
nkeynes@362
   171
#undef signed
nkeynes@362
   172
nkeynes@362
   173
/* inline requires special treatment; it's in C99, and GCC >=2.7 supports
nkeynes@362
   174
   it too, but it's not in C89.  */
nkeynes@362
   175
#undef inline
nkeynes@362
   176
#if __STDC_VERSION__ > 199901L
nkeynes@362
   177
/* it's a keyword */
nkeynes@362
   178
#else
nkeynes@362
   179
# if GCC_VERSION >= 2007
nkeynes@362
   180
#  define inline __inline__   /* __inline__ prevents -pedantic warnings */
nkeynes@362
   181
# else
nkeynes@362
   182
#  define inline  /* nothing */
nkeynes@362
   183
# endif
nkeynes@362
   184
#endif
nkeynes@362
   185
nkeynes@362
   186
/* These are obsolete.  Do not use.  */
nkeynes@362
   187
#ifndef IN_GCC
nkeynes@362
   188
#define CONST		const
nkeynes@362
   189
#define VOLATILE	volatile
nkeynes@362
   190
#define SIGNED		signed
nkeynes@362
   191
nkeynes@362
   192
#define PROTO(type, name, arglist)	type name arglist
nkeynes@362
   193
#define EXFUN(name, proto)		name proto
nkeynes@362
   194
#define DEFUN(name, arglist, args)	name(args)
nkeynes@362
   195
#define DEFUN_VOID(name)		name(void)
nkeynes@362
   196
#define AND		,
nkeynes@362
   197
#define DOTS		, ...
nkeynes@362
   198
#define NOARGS		void
nkeynes@362
   199
#endif /* ! IN_GCC */
nkeynes@362
   200
nkeynes@362
   201
#else	/* Not ANSI C.  */
nkeynes@362
   202
nkeynes@362
   203
#undef  ANSI_PROTOTYPES
nkeynes@362
   204
#define PTR		char *
nkeynes@362
   205
#define PTRCONST	PTR
nkeynes@362
   206
#define LONG_DOUBLE	double
nkeynes@362
   207
nkeynes@362
   208
#define PARAMS(args)		()
nkeynes@362
   209
#define VPARAMS(args)		(va_alist) va_dcl
nkeynes@362
   210
#define VA_START(va_list, var)	va_start(va_list)
nkeynes@362
   211
nkeynes@362
   212
#define VA_OPEN(AP, VAR)		{ va_list AP; va_start(AP); { struct Qdmy
nkeynes@362
   213
#define VA_CLOSE(AP)			} va_end(AP); }
nkeynes@362
   214
#define VA_FIXEDARG(AP, TYPE, NAME)	TYPE NAME = va_arg(AP, TYPE)
nkeynes@362
   215
nkeynes@362
   216
/* some systems define these in header files for non-ansi mode */
nkeynes@362
   217
#undef const
nkeynes@362
   218
#undef volatile
nkeynes@362
   219
#undef signed
nkeynes@362
   220
#undef inline
nkeynes@362
   221
#define const
nkeynes@362
   222
#define volatile
nkeynes@362
   223
#define signed
nkeynes@362
   224
#define inline
nkeynes@362
   225
nkeynes@362
   226
#ifndef IN_GCC
nkeynes@362
   227
#define CONST
nkeynes@362
   228
#define VOLATILE
nkeynes@362
   229
#define SIGNED
nkeynes@362
   230
nkeynes@362
   231
#define PROTO(type, name, arglist)	type name ()
nkeynes@362
   232
#define EXFUN(name, proto)		name()
nkeynes@362
   233
#define DEFUN(name, arglist, args)	name arglist args;
nkeynes@362
   234
#define DEFUN_VOID(name)		name()
nkeynes@362
   235
#define AND		;
nkeynes@362
   236
#define DOTS
nkeynes@362
   237
#define NOARGS
nkeynes@362
   238
#endif /* ! IN_GCC */
nkeynes@362
   239
nkeynes@362
   240
#endif	/* ANSI C.  */
nkeynes@362
   241
nkeynes@362
   242
/* Define macros for some gcc attributes.  This permits us to use the
nkeynes@362
   243
   macros freely, and know that they will come into play for the
nkeynes@362
   244
   version of gcc in which they are supported.  */
nkeynes@362
   245
nkeynes@362
   246
#if (GCC_VERSION < 2007)
nkeynes@362
   247
# define __attribute__(x)
nkeynes@362
   248
#endif
nkeynes@362
   249
nkeynes@362
   250
/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
nkeynes@362
   251
#ifndef ATTRIBUTE_MALLOC
nkeynes@362
   252
# if (GCC_VERSION >= 2096)
nkeynes@362
   253
#  define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
nkeynes@362
   254
# else
nkeynes@362
   255
#  define ATTRIBUTE_MALLOC
nkeynes@362
   256
# endif /* GNUC >= 2.96 */
nkeynes@362
   257
#endif /* ATTRIBUTE_MALLOC */
nkeynes@362
   258
nkeynes@362
   259
/* Attributes on labels were valid as of gcc 2.93. */
nkeynes@362
   260
#ifndef ATTRIBUTE_UNUSED_LABEL
nkeynes@362
   261
# if (GCC_VERSION >= 2093)
nkeynes@362
   262
#  define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
nkeynes@362
   263
# else
nkeynes@362
   264
#  define ATTRIBUTE_UNUSED_LABEL
nkeynes@362
   265
# endif /* GNUC >= 2.93 */
nkeynes@362
   266
#endif /* ATTRIBUTE_UNUSED_LABEL */
nkeynes@362
   267
nkeynes@362
   268
#ifndef ATTRIBUTE_UNUSED
nkeynes@362
   269
#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
nkeynes@362
   270
#endif /* ATTRIBUTE_UNUSED */
nkeynes@362
   271
nkeynes@362
   272
/* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
nkeynes@362
   273
   identifier name.  */
nkeynes@362
   274
#if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
nkeynes@362
   275
# define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
nkeynes@362
   276
#else /* !__cplusplus || GNUC >= 3.4 */
nkeynes@362
   277
# define ARG_UNUSED(NAME) NAME
nkeynes@362
   278
#endif /* !__cplusplus || GNUC >= 3.4 */
nkeynes@362
   279
nkeynes@362
   280
#ifndef ATTRIBUTE_NORETURN
nkeynes@362
   281
#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
nkeynes@362
   282
#endif /* ATTRIBUTE_NORETURN */
nkeynes@362
   283
nkeynes@362
   284
/* Attribute `nonnull' was valid as of gcc 3.3.  */
nkeynes@362
   285
#ifndef ATTRIBUTE_NONNULL
nkeynes@362
   286
# if (GCC_VERSION >= 3003)
nkeynes@362
   287
#  define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
nkeynes@362
   288
# else
nkeynes@362
   289
#  define ATTRIBUTE_NONNULL(m)
nkeynes@362
   290
# endif /* GNUC >= 3.3 */
nkeynes@362
   291
#endif /* ATTRIBUTE_NONNULL */
nkeynes@362
   292
nkeynes@362
   293
/* Attribute `pure' was valid as of gcc 3.0.  */
nkeynes@362
   294
#ifndef ATTRIBUTE_PURE
nkeynes@362
   295
# if (GCC_VERSION >= 3000)
nkeynes@362
   296
#  define ATTRIBUTE_PURE __attribute__ ((__pure__))
nkeynes@362
   297
# else
nkeynes@362
   298
#  define ATTRIBUTE_PURE
nkeynes@362
   299
# endif /* GNUC >= 3.0 */
nkeynes@362
   300
#endif /* ATTRIBUTE_PURE */
nkeynes@362
   301
nkeynes@362
   302
/* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
nkeynes@362
   303
   This was the case for the `printf' format attribute by itself
nkeynes@362
   304
   before GCC 3.3, but as of 3.3 we need to add the `nonnull'
nkeynes@362
   305
   attribute to retain this behavior.  */
nkeynes@362
   306
#ifndef ATTRIBUTE_PRINTF
nkeynes@362
   307
#define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
nkeynes@362
   308
#define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
nkeynes@362
   309
#define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
nkeynes@362
   310
#define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
nkeynes@362
   311
#define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
nkeynes@362
   312
#define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
nkeynes@362
   313
#endif /* ATTRIBUTE_PRINTF */
nkeynes@362
   314
nkeynes@362
   315
/* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL.  A
nkeynes@362
   316
   NULL format specifier was allowed as of gcc 3.3.  */
nkeynes@362
   317
#ifndef ATTRIBUTE_NULL_PRINTF
nkeynes@362
   318
# if (GCC_VERSION >= 3003)
nkeynes@362
   319
#  define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
nkeynes@362
   320
# else
nkeynes@362
   321
#  define ATTRIBUTE_NULL_PRINTF(m, n)
nkeynes@362
   322
# endif /* GNUC >= 3.3 */
nkeynes@362
   323
# define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
nkeynes@362
   324
# define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
nkeynes@362
   325
# define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
nkeynes@362
   326
# define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
nkeynes@362
   327
# define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
nkeynes@362
   328
#endif /* ATTRIBUTE_NULL_PRINTF */
nkeynes@362
   329
nkeynes@362
   330
/* Attribute `sentinel' was valid as of gcc 3.5.  */
nkeynes@362
   331
#ifndef ATTRIBUTE_SENTINEL
nkeynes@362
   332
# if (GCC_VERSION >= 3005)
nkeynes@362
   333
#  define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
nkeynes@362
   334
# else
nkeynes@362
   335
#  define ATTRIBUTE_SENTINEL
nkeynes@362
   336
# endif /* GNUC >= 3.5 */
nkeynes@362
   337
#endif /* ATTRIBUTE_SENTINEL */
nkeynes@362
   338
nkeynes@362
   339
/* We use __extension__ in some places to suppress -pedantic warnings
nkeynes@362
   340
   about GCC extensions.  This feature didn't work properly before
nkeynes@362
   341
   gcc 2.8.  */
nkeynes@362
   342
#if GCC_VERSION < 2008
nkeynes@362
   343
#define __extension__
nkeynes@362
   344
#endif
nkeynes@362
   345
nkeynes@362
   346
#endif	/* ansidecl.h	*/
.