stdarg.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* stdarg.h: ANSI 'C' (X3J11 Oct 88) library header, section 4.8 */
  2. /* Copyright (C) Codemist Ltd., 1988 */
  3. /* Copyright (C) ARM Ltd., 1991-1999. All rights reserved */
  4. /*
  5. * RCS $Revision$
  6. * Checkin $Date$
  7. * Revising $Author: agrant $
  8. */
  9. #ifndef __stdarg_h
  10. #define __stdarg_h
  11. #define __ARMCLIB_VERSION 5060019
  12. #ifndef __STDARG_DECLS
  13. #define __STDARG_DECLS
  14. #undef __CLIBNS
  15. #ifdef __cplusplus
  16. namespace std {
  17. #define __CLIBNS ::std::
  18. extern "C" {
  19. #else
  20. #define __CLIBNS
  21. #endif /* __cplusplus */
  22. /*
  23. * stdarg.h declares a type and defines macros for advancing through a
  24. * list of arguments whose number and types are not known to the called
  25. * function when it is translated. A function may be called with a variable
  26. * number of arguments of differing types. Its parameter list contains one or
  27. * more parameters. The rightmost parameter plays a special role in the access
  28. * mechanism, and will be called parmN in this description.
  29. */
  30. /* N.B. <stdio.h> is required to declare vfprintf() without defining */
  31. /* va_list. Clearly the type __va_list there must keep in step. */
  32. #ifdef __clang__
  33. typedef __builtin_va_list va_list;
  34. #define va_start(ap, param) __builtin_va_start(ap, param)
  35. #define va_end(ap) __builtin_va_end(ap)
  36. #define va_arg(ap, type) __builtin_va_arg(ap, type)
  37. #if __STDC_VERSION__ >= 199900L || __cplusplus >= 201103L || !defined(__STRICT_ANSI__)
  38. #define va_copy(dest, src) __builtin_va_copy(dest, src)
  39. #endif
  40. #else
  41. #ifdef __TARGET_ARCH_AARCH64
  42. typedef struct __va_list {
  43. void *__stack;
  44. void *__gr_top;
  45. void *__vr_top;
  46. int __gr_offs;
  47. int __vr_offs;
  48. } va_list;
  49. #else
  50. typedef struct __va_list { void *__ap; } va_list;
  51. #endif
  52. /*
  53. * an array type suitable for holding information needed by the macro va_arg
  54. * and the function va_end. The called function shall declare a variable
  55. * (referred to as ap) having type va_list. The variable ap may be passed as
  56. * an argument to another function.
  57. * Note: va_list is an array type so that when an object of that type
  58. * is passed as an argument it gets passed by reference.
  59. */
  60. #define va_start(ap, parmN) __va_start(ap, parmN)
  61. /*
  62. * The va_start macro shall be executed before any access to the unnamed
  63. * arguments. The parameter ap points to an object that has type va_list.
  64. * The va_start macro initialises ap for subsequent use by va_arg and
  65. * va_end. The parameter parmN is the identifier of the rightmost parameter
  66. * in the variable parameter list in the function definition (the one just
  67. * before the '...'). If the parameter parmN is declared with the register
  68. * storage class an error is given.
  69. * If parmN is a narrow type (char, short, float) an error is given in
  70. * strict ANSI mode, or a warning otherwise.
  71. * Returns: no value.
  72. */
  73. #define va_arg(ap, type) __va_arg(ap, type)
  74. /*
  75. * The va_arg macro expands to an expression that has the type and value of
  76. * the next argument in the call. The parameter ap shall be the same as the
  77. * va_list ap initialised by va_start. Each invocation of va_arg modifies
  78. * ap so that successive arguments are returned in turn. The parameter
  79. * 'type' is a type name such that the type of a pointer to an object that
  80. * has the specified type can be obtained simply by postfixing a * to
  81. * 'type'. If type is a narrow type, an error is given in strict ANSI
  82. * mode, or a warning otherwise. If the type is an array or function type,
  83. * an error is given.
  84. * In non-strict ANSI mode, 'type' is allowed to be any expression.
  85. * Returns: The first invocation of the va_arg macro after that of the
  86. * va_start macro returns the value of the argument after that
  87. * specified by parmN. Successive invocations return the values of
  88. * the remaining arguments in succession.
  89. * The result is cast to 'type', even if 'type' is narrow.
  90. */
  91. #define __va_copy(dest, src) ((void)((dest) = (src)))
  92. #if !defined(__STRICT_ANSI__) || (defined(__STDC_VERSION__) && 199901L <= __STDC_VERSION__) || (defined(__cplusplus) && 201103L <= __cplusplus)
  93. /* va_copy is in C99 and non-strict C90 and non-strict C++
  94. * __va_copy is always present.
  95. */
  96. #define va_copy(dest, src) ((void)((dest) = (src)))
  97. /* The va_copy macro makes the va_list dest be a copy of
  98. * the va_list src, as if the va_start macro had been applied
  99. * to it followed by the same sequence of uses of the va_arg
  100. * macro as had previously been used to reach the present state
  101. * of src.
  102. */
  103. #endif
  104. #define va_end(ap) __va_end(ap)
  105. /*
  106. * The va_end macro facilitates a normal return from the function whose
  107. * variable argument list was referenced by the expansion of va_start that
  108. * initialised the va_list ap. If the va_end macro is not invoked before
  109. * the return, the behaviour is undefined.
  110. * Returns: no value.
  111. */
  112. #endif /* __clang__ */
  113. #ifdef __cplusplus
  114. } /* extern "C" */
  115. } /* namespace std */
  116. #endif /* __cplusplus */
  117. #ifdef __GNUC__
  118. /* be cooperative with glibc */
  119. typedef __CLIBNS va_list __gnuc_va_list;
  120. #define __GNUC_VA_LIST
  121. #undef __need___va_list
  122. #endif
  123. #endif /* __STDARG_DECLS */
  124. #ifdef __cplusplus
  125. #ifndef __STDARG_NO_EXPORTS
  126. using ::std::va_list;
  127. #endif
  128. #endif /* __cplusplus */
  129. #endif
  130. /* end of stdarg.h */