home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / varargs.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-07  |  4.7 KB  |  168 lines

  1. /***
  2. *varargs.h - XENIX style macros for variable argument functions
  3. *
  4. *       Copyright (c) 1985-2000, 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. *       [Public]
  12. *
  13. ****/
  14.  
  15. #if     _MSC_VER > 1000
  16. #pragma once
  17. #endif
  18.  
  19. #ifndef _INC_VARARGS
  20. #define _INC_VARARGS
  21.  
  22. #if     !defined(_WIN32) && !defined(_MAC)
  23. #error ERROR: Only Mac or Win32 targets supported!
  24. #endif
  25.  
  26.  
  27. #ifdef  _MSC_VER
  28. /*
  29.  * Currently, all MS C compilers for Win32 platforms default to 8 byte
  30.  * alignment.
  31.  */
  32. #pragma pack(push,8)
  33. #endif  /* _MSC_VER */
  34.  
  35. #ifdef  __cplusplus
  36. extern "C" {
  37. #endif
  38.  
  39. #if     __STDC__
  40. #error varargs.h incompatible with ANSI (use stdarg.h)
  41. #endif
  42.  
  43.  
  44. #ifndef _VA_LIST_DEFINED
  45.  
  46. #ifdef  _M_ALPHA
  47. typedef struct {
  48.     char *a0;           /* pointer to first homed integer argument */
  49.     int offset;         /* byte offset of next parameter */
  50. } va_list;
  51. #else
  52. typedef char *va_list;
  53. #endif
  54.  
  55. #define _VA_LIST_DEFINED
  56. #endif
  57.  
  58.  
  59. #if     defined(_M_CEE)
  60.  
  61. #error varargs.h not supported when targetting _M_CEE (use stdarg.h)
  62.  
  63. #elif   defined(_M_IX86)
  64.  
  65. /*
  66.  * define a macro to compute the size of a type, variable or expression,
  67.  * rounded up to the nearest multiple of sizeof(int). This number is its
  68.  * size as function argument (Intel architecture). Note that the macro
  69.  * depends on sizeof(int) being a power of 2!
  70.  */
  71. #define _INTSIZEOF(n)    ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  72.  
  73. #define va_dcl va_list va_alist;
  74. #define va_start(ap) ap = (va_list)&va_alist
  75. #define va_arg(ap,t)    ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  76. #define va_end(ap) ap = (va_list)0
  77.  
  78.  
  79. #elif   defined(_M_MRX000)      /* _MIPS_ */
  80.  
  81.  
  82. #define va_dcl int va_alist;
  83. #define va_start(list) list = (char *) &va_alist
  84. #define va_end(list)
  85. #define va_arg(list, mode) ((mode *)(list =\
  86.  (char *) ((((int)list + (__builtin_alignof(mode)<=4?3:7)) &\
  87.  (__builtin_alignof(mode)<=4?-4:-8))+sizeof(mode))))[-1]
  88. /*  +++++++++++++++++++++++++++++++++++++++++++
  89.     Because of parameter passing conventions in C:
  90.     use mode=int for char, and short types
  91.     use mode=double for float types
  92.     use a pointer for array types
  93.     +++++++++++++++++++++++++++++++++++++++++++ */
  94.  
  95.  
  96. #elif   defined(_M_ALPHA)
  97.  
  98. /*
  99.  * The Alpha compiler supports two builtin functions that are used to
  100.  * implement stdarg/varargs.  The __builtin_va_start function is used
  101.  * by va_start to initialize the data structure that locates the next
  102.  * argument.  The __builtin_isfloat function is used by va_arg to pick
  103.  * which part of the home area a given register argument is stored in.
  104.  * The home area is where up to six integer and/or six floating point
  105.  * register arguments are stored down (so they can also be referenced
  106.  * by a pointer like any arguments passed on the stack).
  107.  */
  108. extern void * __builtin_va_start(va_list, ...);
  109.  
  110. #define va_dcl long va_alist;
  111. #define va_start(list) __builtin_va_start(list, va_alist, 0)
  112. #define va_end(list)
  113. #define va_arg(list, mode) \
  114.     ( *(        ((list).offset += ((int)sizeof(mode) + 7) & -8) , \
  115.         (mode *)((list).a0 + (list).offset - \
  116.                     ((__builtin_isfloat(mode) && (list).offset <= (6 * 8)) ? \
  117.                         (6 * 8) + 8 : ((int)sizeof(mode) + 7) & -8) \
  118.                 ) \
  119.        ) \
  120.     )
  121.  
  122.  
  123. #elif   defined(_M_PPC)
  124.  
  125. /*
  126.  * define a macro to compute the size of a type, variable or expression,
  127.  * rounded up to the nearest multiple of sizeof(int). This number is its
  128.  * size as function argument (PPC architecture). Note that the macro
  129.  * depends on sizeof(int) being a power of 2!
  130.  */
  131. /* this is for LITTLE-ENDIAN PowerPC */
  132.  
  133. /* bytes that a type occupies in the argument list */
  134. #define _INTSIZEOF(n)   ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  135. /* return 'ap' adjusted for type 't' in arglist */
  136. #define _ALIGNIT(ap,t) \
  137.         ((((int)(ap))+(sizeof(t)<8?3:7)) & (sizeof(t)<8?~3:~7))
  138.  
  139. #define va_dcl va_list va_alist;
  140. #define va_start(ap) ap = (va_list)&va_alist
  141. #define va_arg(ap,t)    ( *(t *)((ap = (char *) (_ALIGNIT(ap, t) + _INTSIZEOF(t))) - _INTSIZEOF(t)) )
  142. #define va_end(ap) ap = (va_list)0
  143.  
  144. #else
  145.  
  146. /* A guess at the proper definitions for other platforms */
  147.  
  148. #define _INTSIZEOF(n)    ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
  149.  
  150. #define va_dcl va_list va_alist;
  151. #define va_start(ap) ap = (va_list)&va_alist
  152. #define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
  153. #define va_end(ap) ap = (va_list)0
  154.  
  155.  
  156. #endif
  157.  
  158.  
  159. #ifdef  __cplusplus
  160. }
  161. #endif
  162.  
  163. #ifdef  _MSC_VER
  164. #pragma pack(pop)
  165. #endif  /* _MSC_VER */
  166.  
  167. #endif  /* _INC_VARARGS */
  168.