Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.3 KiB

  1. /***
  2. *varargs.h - XENIX style macros for variable argument functions
  3. *
  4. * Copyright (c) 1985-1994, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file defines XENIX style macros for accessing arguments of a
  8. * function which takes a variable number of arguments.
  9. * [System V]
  10. *
  11. ****/
  12. #ifndef _INC_VARARGS
  13. #define _INC_VARARGS
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #if __STDC__
  18. #error varargs.h incompatible with ANSI (use stdarg.h)
  19. #endif
  20. #ifndef _VA_LIST_DEFINED
  21. #ifdef _M_ALPHA
  22. typedef struct {
  23. char *a0; /* pointer to first homed integer argument */
  24. int offset; /* byte offset of next parameter */
  25. } va_list;
  26. #else
  27. typedef char *va_list;
  28. #endif
  29. #define _VA_LIST_DEFINED
  30. #endif
  31. #if defined(_M_IX86)
  32. /*
  33. * define a macro to compute the size of a type, variable or expression,
  34. * rounded up to the nearest multiple of sizeof(int). This number is its
  35. * size as function argument (Intel architecture). Note that the macro
  36. * depends on sizeof(int) being a power of 2!
  37. */
  38. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  39. #define va_dcl va_list va_alist;
  40. #define va_start(ap) ap = (va_list)&va_alist
  41. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  42. #define va_end(ap) ap = (va_list)0
  43. #elif defined(_M_MRX000) /* _MIPS_ */
  44. #define va_dcl int va_alist;
  45. #define va_start(list) list = (char *) &va_alist
  46. #define va_end(list)
  47. #define va_arg(list, mode) ((mode *)(list =\
  48. (char *) ((((int)list + (__builtin_alignof(mode)<=4?3:7)) &\
  49. (__builtin_alignof(mode)<=4?-4:-8))+sizeof(mode))))[-1]
  50. /* +++++++++++++++++++++++++++++++++++++++++++
  51. Because of parameter passing conventions in C:
  52. use mode=int for char, and short types
  53. use mode=double for float types
  54. use a pointer for array types
  55. +++++++++++++++++++++++++++++++++++++++++++ */
  56. #elif defined(_M_ALPHA)
  57. /*
  58. * The Alpha compiler supports two builtin functions that are used to
  59. * implement stdarg/varargs. The __builtin_va_start function is used
  60. * by va_start to initialize the data structure that locates the next
  61. * argument. The __builtin_isfloat function is used by va_arg to pick
  62. * which part of the home area a given register argument is stored in.
  63. * The home area is where up to six integer and/or six floating point
  64. * register arguments are stored down (so they can also be referenced
  65. * by a pointer like any arguments passed on the stack).
  66. */
  67. extern void * __builtin_va_start(va_list, ...);
  68. #define va_dcl long va_alist;
  69. #define va_start(list) __builtin_va_start(list, va_alist, 0)
  70. #define va_end(list)
  71. #define va_arg(list, mode) \
  72. ( *( ((list).offset += ((int)sizeof(mode) + 7) & -8) , \
  73. (mode *)((list).a0 + (list).offset - \
  74. ((__builtin_isfloat(mode) && (list).offset <= (6 * 8)) ? \
  75. (6 * 8) + 8 : ((int)sizeof(mode) + 7) & -8) \
  76. ) \
  77. ) \
  78. )
  79. #else
  80. /* A guess at the proper definitions for other platforms */
  81. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  82. #define va_dcl va_list va_alist;
  83. #define va_start(ap) ap = (va_list)&va_alist
  84. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  85. #define va_end(ap) ap = (va_list)0
  86. #endif
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif /* _INC_VARARGS */