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.

159 lines
4.4 KiB

  1. /***
  2. *stdarg.h - defines ANSI-style macros for variable argument functions
  3. *
  4. * Copyright (c) 1985-1995, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file defines ANSI-style macros for accessing arguments
  8. * of functions which take a variable number of arguments.
  9. * [ANSI]
  10. *
  11. * [Public]
  12. *
  13. ****/
  14. #ifndef _INC_STDARG
  15. #define _INC_STDARG
  16. #if !defined(_WIN32) && !defined(_MAC)
  17. #error ERROR: Only Mac or Win32 targets supported!
  18. #endif
  19. #ifdef _MSC_VER
  20. /*
  21. * Currently, all MS C compilers for Win32 platforms default to 8 byte
  22. * alignment.
  23. */
  24. #pragma pack(push,8)
  25. #endif /* _MSC_VER */
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #ifndef _VA_LIST_DEFINED
  30. #ifdef _M_ALPHA
  31. typedef struct {
  32. char *a0; /* pointer to first homed integer argument */
  33. int offset; /* byte offset of next parameter */
  34. } va_list;
  35. #else
  36. typedef char * va_list;
  37. #endif
  38. #define _VA_LIST_DEFINED
  39. #endif
  40. #ifdef _M_IX86
  41. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  42. #define va_start(ap,v) ( ap = (va_list)&v + _INTSIZEOF(v) )
  43. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  44. #define va_end(ap) ( ap = (va_list)0 )
  45. #elif defined(_M_MRX000)
  46. /* Use these types and definitions if generating code for MIPS */
  47. #define va_start(ap,v) ap = (va_list)&v + sizeof(v)
  48. #define va_end(list)
  49. #define va_arg(list, mode) ((mode *)(list =\
  50. (char *) ((((int)list + (__builtin_alignof(mode)<=4?3:7)) &\
  51. (__builtin_alignof(mode)<=4?-4:-8))+sizeof(mode))))[-1]
  52. /* +++++++++++++++++++++++++++++++++++++++++++
  53. Because of parameter passing conventions in C:
  54. use mode=int for char, and short types
  55. use mode=double for float types
  56. use a pointer for array types
  57. +++++++++++++++++++++++++++++++++++++++++++ */
  58. #elif defined(_M_ALPHA)
  59. /* Use these types and definitions if generating code for ALPHA */
  60. /*
  61. * The Alpha compiler supports two builtin functions that are used to
  62. * implement stdarg/varargs. The __builtin_va_start function is used
  63. * by va_start to initialize the data structure that locates the next
  64. * argument. The __builtin_isfloat function is used by va_arg to pick
  65. * which part of the home area a given register argument is stored in.
  66. * The home area is where up to six integer and/or six floating point
  67. * register arguments are stored down (so they can also be referenced
  68. * by a pointer like any arguments passed on the stack).
  69. */
  70. extern void * __builtin_va_start(va_list, ...);
  71. #ifdef _CFRONT
  72. #define __builtin_isfloat(a) __builtin_alignof(a)
  73. #endif
  74. #define va_start(list, v) __builtin_va_start(list, v, 1)
  75. #define va_end(list)
  76. #define va_arg(list, mode) \
  77. ( *( ((list).offset += ((int)sizeof(mode) + 7) & -8) , \
  78. (mode *)((list).a0 + (list).offset - \
  79. ((__builtin_isfloat(mode) && (list).offset <= (6 * 8)) ? \
  80. (6 * 8) + 8 : ((int)sizeof(mode) + 7) & -8) \
  81. ) \
  82. ) \
  83. )
  84. #elif defined(_M_PPC)
  85. /* Microsoft C8 front end (used in Motorola Merged compiler) */
  86. /* bytes that a type occupies in the argument list */
  87. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  88. /* return 'ap' adjusted for type 't' in arglist */
  89. #define _ALIGNIT(ap,t) \
  90. ((((int)(ap))+(sizeof(t)<8?3:7)) & (sizeof(t)<8?~3:~7))
  91. #define va_start(ap,v) ( ap = (va_list)&v + _INTSIZEOF(v) )
  92. #define va_arg(ap,t) ( *(t *)((ap = (char *) (_ALIGNIT(ap, t) + _INTSIZEOF(t))) - _INTSIZEOF(t)) )
  93. #define va_end(ap) ( ap = (va_list)0 )
  94. #elif defined(_M_M68K)
  95. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  96. #define va_start(ap,v) ( ap = (va_list)&v + (sizeof(v) < sizeof(int) ? sizeof(v) : _INTSIZEOF(v)) )
  97. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  98. #define va_end(ap) ( ap = (va_list)0 )
  99. #elif defined(_M_MPPC)
  100. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  101. #define va_start(ap,v) ( ap = (va_list)&v + _INTSIZEOF(v) )
  102. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  103. #define va_end(ap) ( ap = (va_list)0 )
  104. #else
  105. /* A guess at the proper definitions for other platforms */
  106. #define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  107. #define va_start(ap,v) ( ap = (va_list)&v + _INTSIZEOF(v) )
  108. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  109. #define va_end(ap) ( ap = (va_list)0 )
  110. #endif
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #ifdef _MSC_VER
  115. #pragma pack(pop)
  116. #endif /* _MSC_VER */
  117. #endif /* _INC_STDARG */