Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
SysTypes.h
Go to the documentation of this file.
1 
10 #ifndef _INC_SysTypes_H
11 #define _INC_SysTypes_H
12 #ifndef NO_PRAGMA_ONCE
13 #pragma once
14 #endif
15 
26 
27 // M$ compiler versions:
28 // _MSC_VER=1000 = VS5 = can do "#pragma once",
29 // _MSC_VER=1200 = VS6
30 // _MSC_VER=1202 = eVC++4
31 // _MSC_VER=1300 = VC++ 7.0, NET 2002, can do "__super"
32 // _MSC_VER=1310 = VC++ 7.1, NET 2003
33 // _MSC_VER=1400 = VC++ 8 = VS 2005,
34 // _MSC_VER=1500 = VC++ 9 = VS 2008, (PlatformToolset = 90)
35 // _MSC_VER=1600 = VC++ 10 = VS 2010, (PlatformToolset = 100)
36 // _MSC_VER=1700 = VC++ 12 = VS 2012, compiler is 17.00.51106.1
37 // _MSC_VER=1800 = VC++ 13 = VS 2013,
38 // _MSC_VER=1900 = VS v14 = VS 2015, (PlatformToolset = 140)
39 // _MSC_VER=1910 = VS v15 = VS 2017, (PlatformToolset = 141)
40 // _MSC_VER=19xx = VS v16 = VS 2019, (PlatformToolset = 142)
41 
42 // what platform/OS target version of windows minimum/assumed?
43 // Windows 95 _WIN32_WINDOWS>=0x0400, WINVER>=0x0400
44 // Windows NT 4.0 _WIN32_WINNT>=0x0400, WINVER>=0x0400
45 // Windows 98 _WIN32_WINDOWS>=0x0410, WINVER>=0x0410
46 // Windows Me _WIN32_WINDOWS=0x0500, WINVER>=0x0500
47 // Windows 2000 _WIN32_WINNT>=0x0500, WINVER>=0x0500
48 // Windows XP _WIN32_WINNT>=0x0501, WINVER>=0x0501
49 // Windows Server 2003 _WIN32_WINNT>=0x0502, WINVER>=0x0502
50 // Windows Vista _WIN32_WINNT>=0x0600, WINVER>=0x0600 (lowest we support 2017)
51 // Windows 7 _WIN32_WINNT>=0x0601, WINVER>=0x0601
52 // Windows Server 2012 (NT 6.2)
53 // Windows 8 _WIN32_WINNT>=0x0602, WINVER>=0x0602 (NT 6.2)
54 // Windows 8.1
55 // Windows 10 _WIN32_WINNT>=0x0A00, WINVER>=0x0A00
56 
57 // Other external #define(s) observed:
58 // __linux__ = Build for Linux OS.
59 // _DEBUG = debug code. generated by compiler 7 on /MTd or /Mdd option. These options specify debug versions of the C run-time library
60 // _WIN32 = Build for Windows OS. Is defined for both 64 and 32 bit versions. generated by compiler 7 on.
61 // WIN32 = use _WIN32 instead although some code seems to look at this as well. Deprecated?
62 // _WIN64 = 64 bit windows. will also set USE_64BIT and _WIN32
63 // _M_IX86, _M_X64, _M_AMD64 = what processor type assumed? _M_IX86 only for use of _asm
64 // _MT = multi-threaded vs. single-threaded ? ASSUME __linux__ IS ALWAYS _MT. non _MT may be deprecated?
65 // __GNUC__ = using the GCC GNU C compiler (uses __asm__) May work for _WIN32 or __linux__
66 //
67 // other compilers:
68 // __MINGW32__, __BORLANDC__, __WATCOMC__
69 
70 #if defined(_MSC_VER) && (_MSC_VER >= 1000)
71 // Remove globally annoying warnings.
72 #pragma warning(disable:4800) // "forcing value to bool 'true' or 'false' (performance warning)" (convert BOOL/int to bool)
73 #pragma warning(disable:4251) // 'CC' needs to have DLL - interface to be used by clients of class 'Gray::HResult' (FOR DLLs ONLY and inline type children)
74 
75 // Useless MSVC2010 warnings: at /W4 level
76 #pragma warning(disable:4510) // default constructor could not be generated
77 #pragma warning(disable:4512) // assignment operator could not be generated
78 #pragma warning(disable:4610) // class 'Gray::cTypeInfo' can never be instantiated - user defined constructor required
79 
80 #endif // _MSC_VER >= 1000
81 
82 #ifndef USE_CRT
83 #define USE_CRT 1 // 1 = use all normal CRT functions. 0 = attempt to use minimal/no CRT.
84 #endif
85 
86 // Define your compiler here.
87 #ifdef _MSC_VER
88 // MSVC 1900
89 #define GRAY_COMPILER_NAME "Msc"
90 #define GRAY_COMPILER_VER _MSC_VER
91 
92 #elif defined(__GNUC__)
93 // GNU 4.5 = 40500
94 #define GRAY_COMPILER_NAME "gnuc"
95 #define GRAY_COMPILER_VER (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
96 #undef __STRICT_ANSI__
97 
98 #elif defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)
99 #define GRAY_COMPILER_NAME "cc" // other ?
100 #define GRAY_COMPILER_VER 0
101 #error UNSUPPORTED COMPILER
102 
103 #else
104 #error UNKNOWN COMPILER
105 #endif
106 
107 // http://en.wikipedia.org/wiki/Pragma_once
108 #if defined(_MSC_VER) && (_MSC_VER < 1000)
109 #define NO_PRAGMA_ONCE // This MUST be put on the command line.
110 #endif
111 #if defined(__GNUC__) && (GRAY_COMPILER_VER >= 30400) // >= 3.4
112 // #define NO_PRAGMA_ONCE
113 #define _NATIVE_WCHAR_T_DEFINED // This seems to be true in newer versions. wchar_t
114 #endif
115 
116 #ifdef _WIN32
117 
118 #ifdef UNDER_CE
119 
120 #define WINCE // Some code depends on this ?
121 #pragma comment(linker, "/nodefaultlib:libc.lib")
122 #pragma comment(linker, "/nodefaultlib:libcd.lib")
123 // NOTE - this value is not strongly correlated to the Windows CE OS version being targeted
124 #define _WIN32_WCE 0x0500
125 #define WINVER _WIN32_WCE
126 #include <ceconfig.h> // __CECONFIG_H__
127 
128 #else // UNDER_CE
129 
130 #if 0
131 // Including SDKDDKVer.h defines the highest available Windows platform.
132 // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
133 // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
134 #include <SDKDDKVer.h>
135 #else
136 
137 // Modify the following defines if you have to target a platform prior to the ones specified below.
138 // Refer to MSDN for the latest info on corresponding values for different platforms.
139 #ifndef WINVER // Allow use of features specific to Windows XP or later.
140 #define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. (0x0600 = Vista or higher)
141 #endif
142 #ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
143 #define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows.
144 #endif
145 #ifndef _WIN32_WINDOWS // Allow use of features specific to Windows XP or later.
146 #define _WIN32_WINDOWS 0x0600 // Change this to the appropriate value to target Windows Me or later.
147 #endif
148 #ifndef _WIN32_IE // Allow use of features specific to Windows IE version.
149 #define _WIN32_IE 0x0700 // Change this to the appropriate value to target IE 7 or later. (default for Vista)
150 #endif
151 
152 #endif // SDKDDKVer.h
153 
154 #endif // ! UNDER_CE
155 
156 #define _WINSOCKAPI_ // prevent _WINSOCKAPI_ from loading because i want _WINSOCK2API_
157 // #define WINBASE_DECLARE_GET_MODULE_HANDLE_EX // allow GetModuleHandleEx
158 #ifndef STRICT
159 #define STRICT 1 // Make sure DECLARE_HANDLE has type info.
160 #endif
161 
162 #ifdef _DEBUG
163 #define DEBUG_VALIDATE_ALLOC // slows us down but checks memory often
164 #endif
165 
166 #ifdef _AFXDLL // will define _MFC_VER
167 #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
168 
169 // Windows with MFC (NON GUI)
170 #ifndef __AFX_H__ // not already included
171 #include <afx.h> // MFC core and standard components. MFC Strings. CString. defines _MFC_VER
172 #endif
173 #ifndef _MFC_VER // should be defined in <afxver_.h> in <afx.h>
174 #error NO _MFC_VER?
175 #endif
176 #include <afxtempl.h> // MFC Templates. CArray.
177 #include <Winsock2.h> // must get loaded before <afxwin.h> to prevent problems with _WINSOCKAPI_ vs _WINSOCK2API_ in VC2013 with _AFXDLL, _MFC_VER
178 
179 #else
180 #include <windows.h>
181 #endif // ! _AFXDLL
182 
183 // TODO : Include SysRes.h from here !?????
184 
185 #if defined(_WIN32) && ! defined(_WINDOWS_)
186 #ifdef _WINDOWS_H // __GNUC__ version of "windows.h"
187 #define _WINDOWS_
188 #elif defined(__WINDOWS__) // UNDER_CE version
189 #define _WINDOWS_
190 #elif ! defined(_WINDOWS_) // should be defined in <afx.h> !
191 #error NO _WINDOWS_ defined?
192 #endif
193 #endif
194 
195 #endif // _WIN32
196 
197 //*******************************************
198 // ASSUME these ANSI C standard types are universal. rely on CRT.
199 
200 #include <stddef.h> // offsetof(), size_t
201 #include <stdlib.h> // _MAX_PATH, __max(), __min() if !defined(__OpenBSD__) ?
202 #include <string.h> // memcpy()
203 #include <stdarg.h> // va_list ...
204 #include <limits.h> // INT_MAX, (PATH_MAX in Linux) is std::numeric_limits<T>::max() in <limits> better ?
205 
206 #if USE_CRT
207 #include <stdio.h> // define FILE _vsnprintf_s printf() function
208 #endif
209 
210 #ifdef UNDER_CE
211 #include <new>
212 #else
213 #include <assert.h> // assert() (no idea why UNDER_CE doesn't like this)
214 #endif
215 
216 #ifdef __GNUC__
217 #include <stdint.h> // int64_t in C99 standard.
218 #define _CPPUNWIND // exceptions are supported
219 #define _CPPRTTI // RTTI is supported
220 #define _MT // __linux__ and __GNUC__ is always considered to be multi-threaded.
221 #endif // __GNUC__
222 
223 #ifdef __linux__ // emulate windows type stuff for Linux.
224 // __linux__, Linux or _BSD
225 #include <signal.h>
226 #include <sched.h>
227 #include <fcntl.h> // open()
228 #include <unistd.h> // gethostname()
229 #include <linux/unistd.h>
230 #endif
231 
232 #if defined(_WIN32) && !defined(UNDER_CE) && ! defined(__GNUC__) && USE_CRT
233 #include <crtdbg.h>
234 #include <direct.h> // _chdir
235 #endif
236 
237 #ifndef RC_INVOKED
238 
239 // see cMemT::NtoH() and cMemT::HtoN() for auto conversion to big endian (network)
240 // e.g. on little endian (Intel). 0x123456 = 56 34 12 00
241 #if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(_M_IA64) || defined(_AMD64_) || defined(__ia64__) || defined(__x86_64__)
242 #define USE_INTEL 1
243 #define USE_LITTLE_ENDIAN 1
244 #endif
245 
248 #if defined(_WIN64)
249 #define USE_64BIT
250 #elif defined(_MSC_VER) && ( defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64))
251 #define USE_64BIT
252 #elif defined(__GNUC__) && ( \
253  defined(__amd64__) || defined(__x86_64__) || \
254  defined(__ppc64__) || defined(__powerpc64__) || \
255  defined(__ia64__) || defined(__alpha__) || \
256  (defined(__sparc__) && defined(__arch64__)) || \
257  defined(__s390x__) || defined(__mips64) )
258 #define USE_64BIT
259 #endif
260 
261 #define USE_FLOAT // Assume we can do float and double types. Some embedded systems don't support float types. probably ieee .
262 
263 // Assume we do native int64 types though we may not be true 64 bit code.
264 // What cases don't we do native 64 bit int types ?
265 #define USE_INT64
266 
267 #if defined(__GNUC__) && defined(USE_64BIT)
268 #define USE_LONG_AS_INT64
269 #endif
270 
271 //********************************
272 
273 #if defined(_WIN32) && ! defined(WIN32)
274 #define WIN32 // Some external stuff needs this alternate define. like JS (JavaScript)
275 #endif
276 #if defined(DEBUG) && ! defined(_DEBUG)
277 #define _DEBUG // Make sure everyone uses this define.
278 #endif
279 
280 #if defined(_MSC_VER) || defined(__BORLANDC__)
281 #define __DECL_EXPORT __declspec(dllexport) // exported from in a DLL
282 #define __DECL_IMPORT __declspec(dllimport) // in a DLL
283 #define __DECL_ALIGN(x) __declspec(align(x))
284 #elif defined (__GNUC__)
285 // #define __declspec(x)
286 #define __DECL_EXPORT //__declspec(dllexport)
287 #define __DECL_IMPORT //__declspec(dllimport)
288 #define __DECL_ALIGN(x)
289 #elif defined(__WATCOMC__)
290 #define __declspec(x)
291 #define __DECL_EXPORT //__export
292 #define __DECL_IMPORT //__import
293 #define __DECL_ALIGN(x)
294 #else
295 #error UNKNOWN COMPILER
296 #endif
297 
298 #ifndef UNREFERENCED_PARAMETER
299 #define UNREFERENCED_PARAMETER(P) ((void)(P))
300 #endif
301 
302 // This should NEVER execute. Suppress warning if i put code here because the compiler knows its not reachable!? Or if i don't.
303 #if defined(_MSC_VER)
304 #define UNREACHABLE_CODE(x) __assume(0) // M$ emulate the GCC __builtin_unreachable.
305 #elif defined(__GNUC__) && (GRAY_COMPILER_VER >= 40500)
306 #define UNREACHABLE_CODE(x) __builtin_unreachable() // __GNUC__ Defines __builtin_unreachable() natively. use it.
307 #else
308 // no_return
309 #define UNREACHABLE_CODE(x) ASSERT(0); x // has nothing like this. But
310 #endif
311 
312 #ifdef __GNUC__
313 #define ES_AWAYMODE_REQUIRED ((DWORD)0x00000040)
314 #define UNREFERENCED_REFERENCE(x) ((void)(x)) // references don't work with the normal UNREFERENCED_PARAMETER() macro !??
315 #elif ( _MSC_VER > 1600 )
316 #define UNREFERENCED_REFERENCE UNREFERENCED_PARAMETER // This doesn't work for VS2010 if type is not fully defined! ( _MSC_VER > 1600 )
317 #else
318 #define UNREFERENCED_REFERENCE(x) ((void)(&x)) // x doesn't work for VS2010 if type is not fully defined! ( _MSC_VER > 1600 )
319 #endif
320 
321 #ifndef DECLSPEC_NOVTABLE // __GNUC__ has no such concept. Maybe use pragma ? AFX_NOVTABLE
322 #define DECLSPEC_NOVTABLE //__declspec(novtable) // This is a abstract class or an interface the may not be instantiated directly.
323 #endif
324 
325 // NOTE: __interface seems to imply base on IUnknown in M$. DONT use it! Use MIDL_INTERFACE(a) instead.
326 // _MSC_VER has a bug __declspec(dllexport) a class based on a __interface. can't create = operator ?
327 
328 #ifndef DECLARE_INTERFACE // for __GNUC__ (or CINTERFACE)
329 #define interface struct DECLSPEC_NOVTABLE // a plain interface that may not support IUnknown. For use with DirectX defs.
330 #define DECLARE_INTERFACE(iface) interface iface
331 #define DECLARE_INTERFACE_(iface, baseiface) interface iface : public baseiface
332 #endif
333 
334 #if defined(_MSC_VER) && ( _MSC_VER < 1100 ) // MSC Version 5.0 defines these from the ANSI spec. MSC 4.1 does not.
335 #define bool int
336 #define false 0
337 #define true 1
338 #endif // _MSC_VER
339 
340 #if defined(_MSC_VER) && (_MSC_VER < 1300)
341 typedef LONG LONG_PTR;
342 #endif
343 
344 // fixed size on all platforms.
345 // http://msdn2.microsoft.com/en-us/library/aa384264.aspx
346 
347 #ifdef __linux__ // emulate windows type names
348 
349 // dummy out __GNUC__ non keywords.
350 #define _cdecl
351 #define __cdecl
352 #define _stdcall
353 #define __stdcall
354 #define IN // document direction/usage of params. (const) AKA _In_
355 #define OUT // aka _Out_
356 #define FAR // Not used in modern architectures anymore but M$ headers use this. ignore it.
357 
358 // Missing Windows header file stuff.
359 typedef int BOOL; // match with sqltypes.h and _WIN32
360 
361 typedef unsigned char BYTE; // always 8 bits
362 typedef unsigned short WORD; // always 16 bits
363 #ifdef USE_64BIT
364 typedef unsigned int DWORD; // not sure if 32 or 64 bits ? always 32 bits in _WIN32 but defined in Linux sqltypes.h as (long unsigned int)
365 #else
366 typedef unsigned long DWORD; // In 32 bit code this is 32 bits. Match sqltypes.h.
367 #endif
368 
369 typedef signed short INT16;
370 typedef unsigned short UINT16;
371 
372 typedef __int32_t INT32; // always 32 bits.
373 typedef __uint32_t UINT32; // always 32 bits.
374 
375 #ifdef USE_INT64
376 typedef __int64_t INT64; // always 64 bits if USE_INT64. AKA "long long int"
377 typedef __uint64_t UINT64; // always 64 bits. AKA "unsigned long long int"
378 #endif
379 
380 typedef char TCHAR;
381 
382 // Basic common types. variable/vaguely sized. (e.g. 64 or 32 bits)
383 typedef unsigned int UINT; // probably 32 bits.
384 typedef long LONG;
385 typedef unsigned long ULONG; // ULONG may be equiv to UINT32 or UINT64. check USE_LONG_AS_INT64
386 
387 // portable types that are safe if 32 or 64 bits. large enough to hold a pointer.
388 typedef size_t UINT_PTR; // USE_64BIT ?
389 typedef ptrdiff_t INT_PTR; // USE_64BIT ?
390 typedef long LONG_PTR; // USE_64BIT ?
391 typedef unsigned long ULONG_PTR; // Same as DWORD_PTR
392 typedef unsigned long DWORD_PTR; // Same as ULONG_PTR
393 
394 // normally in <windef.h>
395 #define MAKEWORD(l,h) ((WORD)(((BYTE)(l)) | ((WORD)((BYTE)(h))) << 8))
396 #define MAKELONG(low, high) ((LONG)(((WORD)(low)) | (((LONG)((WORD)(high))) << 16)))
397 
398 #define LOWORD(l) ((WORD)(l))
399 #define HIWORD(l) ((WORD)(((UINT32)(l) >> 16) & 0xFFFF))
400 #define LOBYTE(w) ((BYTE)(((WORD)(w))&0xFF))
401 #define HIBYTE(w) ((BYTE)(((WORD)(w))>>8))
402 
403 #define CALLBACK GRAYCALL // just make this the same as GRAYCALL
404 #define STDMETHODCALLTYPE GRAYCALL // just make this the same as GRAYCALL
405 
406 #define _MAX_PATH PATH_MAX // #include <limits.h> or MAX_PATH in windef.h. (Put this in Filepath.h ?) FILENAME_MAX ?
407 
408 #endif
409 
410 #if defined(__GNUC__) || defined(UNDER_CE)
411 #define _Inout_ // just stub this out.
412 #define _countof(a) ((size_t)(sizeof(a)/sizeof((a)[0])))
413 #endif
414 
415 #ifdef __GNUC__
416 #define nullptr __null // This is a void* not an int value.
417 #elif defined(_MSC_VER) && ( _MSC_VER < 1700 ) && ! defined(__cplusplus_cli)
419 #define nullptr NULL //
420 #endif
421 
422 #ifndef _MAX_PATH
423 #define _MAX_PATH 260 // __GNUC__ can leave this out if __STRICT_ANSI__
424 #endif
425 
426 #ifdef UNDER_CE
427 #define VOLATILE
428 #else
429 #define VOLATILE volatile
430 #endif
431 
432 // Largest integral sized type. NOT always the fastest. use USE_64BIT
433 #ifdef USE_INT64
434 typedef INT64 INTMAX_t; // 64 bits if USE_INT64 not just USE_64BIT
435 typedef UINT64 UINTMAX_t; // 64 bits
436 #elif defined(_WIN16)
437 typedef INT16 INTMAX_t; // 16 bits
438 typedef UINT16 UINTMAX_t; // 16 bits
439 #else // else assume we can do 32 bits.
440 typedef INT32 INTMAX_t; // 32 bits if NOT USE_INT64
441 typedef UINT32 UINTMAX_t; // 32 bits
442 #endif
443 
444 #ifndef _UINTPTR_T_DEFINED
445 #define _UINTPTR_T_DEFINED
446 #ifdef USE_64BIT
447 typedef UINT64 uintptr_t; // 64 bits. like size_t or intptr_t. maybe needs to be aligned to be truly fast? _SIZEOF_PTR should be the same as sizeof(size_t)
448 #else
449 typedef UINT32 uintptr_t; // 32 bits. like size_t or intptr_t. _SIZEOF_PTR should be the same as sizeof(size_t).
450 #endif
451 #endif
452 
453 // These must be made to work for both longs and ints. implement as macro not code.
454 // use "#include <xutility>" or "#include <minmax.h>" ?
455 #ifndef MAX
456 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
457 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
458 #endif
459 #ifndef ABS
460 #define ABS(n) (((n) < 0) ? (-(n)) : (n)) // no conflict with <math.h> abs()
461 #endif // sign
462 
463 #ifndef _HRESULT_DEFINED
464 #define _HRESULT_DEFINED
465 typedef INT32 HRESULT;
466 #endif // _HRESULT_DEFINED
467 
468 #endif // RC_INVOKED
469 #endif // _INC_SysTypes_H
UINT64 UINTMAX_t
Definition: SysTypes.h:435
INT64 INTMAX_t
Definition: SysTypes.h:434
UINT32 uintptr_t
Definition: SysTypes.h:449
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465