STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
vadefs.h
Go to the documentation of this file.
1 //
2 // vadefs.h
3 //
4 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //
6 // Definitions of macro helpers used by <stdarg.h>. This is the topmost header
7 // in the CRT header lattice, and is always the first CRT header to be included,
8 // explicitly or implicitly. Therefore, this header also has several definitions
9 // that are used throughout the CRT.
10 //
11 #pragma once
12 #define _INC_VADEFS
13 
14 #define _CRT_PACKING 8
15 #pragma pack(push, _CRT_PACKING)
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #if !defined _W64
22 #define _W64
23 #endif
24 
25 #ifndef _UINTPTR_T_DEFINED
26  #define _UINTPTR_T_DEFINED
27  #ifdef _WIN64
28  typedef unsigned __int64 uintptr_t;
29  #else
30  typedef unsigned int uintptr_t;
31  #endif
32 #endif
33 
34 #ifndef _VA_LIST_DEFINED
35  #define _VA_LIST_DEFINED
36  #ifdef _M_CEE_PURE
37  typedef System::ArgIterator va_list;
38  #else
39  typedef char* va_list;
40  #endif
41 #endif
42 
43 #ifdef __cplusplus
44  #define _ADDRESSOF(v) (&const_cast<char&>(reinterpret_cast<const volatile char&>(v)))
45 #else
46  #define _ADDRESSOF(v) (&(v))
47 #endif
48 
49 #if defined _M_ARM && !defined _M_CEE_PURE
50  #define _VA_ALIGN 4
51  #define _SLOTSIZEOF(t) ((sizeof(t) + _VA_ALIGN - 1) & ~(_VA_ALIGN - 1))
52  #define _APALIGN(t,ap) (((va_list)0 - (ap)) & (__alignof(t) - 1))
53 #elif defined _M_ARM64 && !defined _M_CEE_PURE
54  #define _VA_ALIGN 8
55  #define _SLOTSIZEOF(t) ((sizeof(t) + _VA_ALIGN - 1) & ~(_VA_ALIGN - 1))
56  #define _APALIGN(t,ap) (((va_list)0 - (ap)) & (__alignof(t) - 1))
57 #else
58  #define _SLOTSIZEOF(t) (sizeof(t))
59  #define _APALIGN(t,ap) (__alignof(t))
60 #endif
61 
62 #if defined _M_CEE_PURE || (defined _M_CEE && !defined _M_ARM && !defined _M_ARM64)
63 
64  void __cdecl __va_start(va_list*, ...);
65  void* __cdecl __va_arg(va_list*, ...);
66  void __cdecl __va_end(va_list*);
67 
68  #define __crt_va_start_a(ap, v) ((void)(__va_start(&ap, _ADDRESSOF(v), _SLOTSIZEOF(v), __alignof(v), _ADDRESSOF(v))))
69  #define __crt_va_arg(ap, t) (*(t *)__va_arg(&ap, _SLOTSIZEOF(t), _APALIGN(t,ap), (t*)0))
70  #define __crt_va_end(ap) ((void)(__va_end(&ap)))
71 
72 #elif defined _M_IX86
73 
74  #define _INTSIZEOF(n) ((sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1))
75 
76  #define __crt_va_start_a(ap, v) ((void)(ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v)))
77  #define __crt_va_arg(ap, t) (*(t*)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)))
78  #define __crt_va_end(ap) ((void)(ap = (va_list)0))
79 
80 #elif defined _M_ARM
81 
82  #ifdef __cplusplus
83  void __cdecl __va_start(va_list*, ...);
84  #define __crt_va_start_a(ap, v) ((void)(__va_start(&ap, _ADDRESSOF(v), _SLOTSIZEOF(v), _ADDRESSOF(v))))
85  #else
86  #define __crt_va_start_a(ap, v) ((void)(ap = (va_list)_ADDRESSOF(v) + _SLOTSIZEOF(v)))
87  #endif
88 
89  #define __crt_va_arg(ap, t) (*(t*)((ap += _SLOTSIZEOF(t) + _APALIGN(t,ap)) - _SLOTSIZEOF(t)))
90  #define __crt_va_end(ap) ((void)(ap = (va_list)0))
91 
92 #elif defined _M_ARM64
93 
94  void __cdecl __va_start(va_list*, ...);
95 
96  #define __crt_va_start_a(ap,v) ((void)(__va_start(&ap, _ADDRESSOF(v), _SLOTSIZEOF(v), __alignof(v), _ADDRESSOF(v))))
97  #define __crt_va_arg(ap, t) \
98  ((sizeof(t) > (2 * sizeof(__int64))) \
99  ? **(t**)((ap += sizeof(__int64)) - sizeof(__int64)) \
100  : *(t*)((ap += _SLOTSIZEOF(t) + _APALIGN(t,ap)) - _SLOTSIZEOF(t)))
101  #define __crt_va_end(ap) ((void)(ap = (va_list)0))
102 
103 
104 #elif defined _M_X64
105 
106  void __cdecl __va_start(va_list* , ...);
107 
108  #define __crt_va_start_a(ap, x) ((void)(__va_start(&ap, x)))
109  #define __crt_va_arg(ap, t) \
110  ((sizeof(t) > sizeof(__int64) || (sizeof(t) & (sizeof(t) - 1)) != 0) \
111  ? **(t**)((ap += sizeof(__int64)) - sizeof(__int64)) \
112  : *(t* )((ap += sizeof(__int64)) - sizeof(__int64)))
113  #define __crt_va_end(ap) ((void)(ap = (va_list)0))
114 
115 #endif
116 
117 #ifdef __cplusplus
118 } // extern "C"
119 #endif
120 
121 #if defined __cplusplus && !defined _CRT_NO_VA_START_VALIDATION
122  extern "C++"
123  {
124  template <typename _Ty>
125  struct __vcrt_va_list_is_reference
126  {
127  enum : bool { __the_value = false };
128  };
129 
130  template <typename _Ty>
131  struct __vcrt_va_list_is_reference<_Ty&>
132  {
133  enum : bool { __the_value = true };
134  };
135 
136  template <typename _Ty>
137  struct __vcrt_va_list_is_reference<_Ty&&>
138  {
139  enum : bool { __the_value = true };
140  };
141 
142  template <typename _Ty>
143  void __vcrt_va_start_verify_argument_type() throw()
144  {
145  static_assert(!__vcrt_va_list_is_reference<_Ty>::__the_value, "va_start argument must not have reference type and must not be parenthesized");
146  }
147  } // extern "C++"
148 
149  #define __crt_va_start(ap, x) ((void)(__vcrt_va_start_verify_argument_type<decltype(x)>(), __crt_va_start_a(ap, x)))
150 
151 #else // ^^^ __cplusplus ^^^ // vvv !__cplusplus vvv //
152 
153  #define __crt_va_start(ap, x) __crt_va_start_a(ap, x)
154 
155 #endif
156 
157 #pragma pack(pop)
unsigned int uintptr_t
Definition: vadefs.h:30
char * va_list
Definition: vadefs.h:39