home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / stdarg.h < prev    next >
C/C++ Source or Header  |  1998-06-17  |  5KB  |  174 lines

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