Skip to content

Commit a7c55f1

Browse files
authored
[CORE] Add a stdint adapter (#712)
1 parent cfbdf62 commit a7c55f1

File tree

6 files changed

+193
-21
lines changed

6 files changed

+193
-21
lines changed

Core/Libraries/Include/Lib/BaseTypeCore.h

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
// TheSuperHackers @compile feliwir 07/04/2025 Adds utility macros for cross-platform compatibility
3838
#include <Utility/compat.h>
3939
#include <Utility/CppMacros.h>
40+
#include <Utility/stdint_adapter.h>
4041

4142
/*
4243
** Turn off some unneeded warnings.
@@ -124,22 +125,17 @@
124125
//--------------------------------------------------------------------
125126
// Fundamental type definitions
126127
//--------------------------------------------------------------------
127-
typedef float Real; // 4 bytes
128-
typedef int Int; // 4 bytes
129-
typedef unsigned int UnsignedInt; // 4 bytes
130-
typedef unsigned short UnsignedShort; // 2 bytes
131-
typedef short Short; // 2 bytes
132-
typedef unsigned char UnsignedByte; // 1 byte USED TO BE "Byte"
133-
typedef char Byte; // 1 byte USED TO BE "SignedByte"
134-
typedef char Char; // 1 byte of text
135-
typedef bool Bool; //
128+
typedef float Real; // 4 bytes
129+
typedef int32_t Int; // 4 bytes
130+
typedef uint32_t UnsignedInt; // 4 bytes
131+
typedef uint16_t UnsignedShort; // 2 bytes
132+
typedef int16_t Short; // 2 bytes
133+
typedef unsigned char UnsignedByte; // 1 byte USED TO BE "Byte"
134+
typedef char Byte; // 1 byte USED TO BE "SignedByte"
135+
typedef char Char; // 1 byte of text
136+
typedef bool Bool; //
136137
// note, the types below should use "long long", but MSVC doesn't support it yet
137-
#ifdef _MSC_VER
138-
typedef __int64 Int64; // 8 bytes
139-
typedef unsigned __int64 UnsignedInt64; // 8 bytes
140-
#else
141-
typedef long long Int64; // 8 bytes
142-
typedef unsigned long long UnsignedInt64; // 8 bytes
143-
#endif
138+
typedef int64_t Int64; // 8 bytes
139+
typedef uint64_t UnsignedInt64; // 8 bytes
144140

145141
#endif // _BASE_TYPE_CORE_H_

Core/Libraries/Source/WWVegas/WWLib/Vector.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ template<class T>
317317
inline int VectorClass<T>::ID(T const * ptr)
318318
{
319319
if (!IsValid) return(0);
320-
return(((unsigned long)ptr - (unsigned long)&(*this)[0]) / sizeof(T));
320+
return(((uintptr_t)ptr - (uintptr_t)&(*this)[0]) / sizeof(T));
321321
}
322322

323323

Core/Libraries/Source/WWVegas/WWLib/always.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
// TheSuperHackers @compile feliwir 17/04/2025 include utility macros for cross-platform compatibility
4747
#include <Utility/compat.h>
48+
#include <Utility/stdint_adapter.h>
4849

4950
// Disable warning about exception handling not being enabled. It's used as part of STL - in a part of STL we don't use.
5051
#pragma warning(disable : 4530)

Core/Libraries/Source/WWVegas/WWLib/wwstring.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ StringClass::Get_String (int length, bool is_temp)
101101
//
102102
// Grab this unused buffer for our string
103103
//
104-
unsigned long temp_string=reinterpret_cast<unsigned long>(m_TempStrings);
104+
uintptr_t temp_string=reinterpret_cast<uintptr_t>(m_TempStrings);
105105
temp_string+=MAX_TEMP_BYTES*MAX_TEMP_STRING;
106106
temp_string&=~(MAX_TEMP_BYTES*MAX_TEMP_STRING-1);
107107
temp_string+=index*MAX_TEMP_BYTES;
@@ -196,8 +196,8 @@ StringClass::Free_String (void)
196196
{
197197
if (m_Buffer != m_EmptyString) {
198198

199-
unsigned long buffer_base=reinterpret_cast<unsigned long>(m_Buffer-sizeof (StringClass::_HEADER));
200-
unsigned long temp_base=reinterpret_cast<unsigned long>(m_TempStrings+MAX_TEMP_BYTES*MAX_TEMP_STRING);
199+
uintptr_t buffer_base=reinterpret_cast<uintptr_t>(m_Buffer-sizeof (StringClass::_HEADER));
200+
uintptr_t temp_base=reinterpret_cast<uintptr_t>(m_TempStrings+MAX_TEMP_BYTES*MAX_TEMP_STRING);
201201

202202
if ((buffer_base>>11)==(temp_base>>11)) {
203203
m_Buffer[0] = 0;

Core/Tools/WW3D/pluglib/Vector.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ template<class T>
303303
inline int VectorClass<T>::ID(T const * ptr)
304304
{
305305
if (!IsValid) return(0);
306-
return(((unsigned long)ptr - (unsigned long)&(*this)[0]) / sizeof(T));
306+
return(((uintptr_t)ptr - (uintptr_t)&(*this)[0]) / sizeof(T));
307307
}
308308

309309

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
** Command & Conquer Generals Zero Hour(tm)
3+
** Copyright 2025 TheSuperHackers
4+
**
5+
** This program is free software: you can redistribute it and/or modify
6+
** it under the terms of the GNU General Public License as published by
7+
** the Free Software Foundation, either version 3 of the License, or
8+
** (at your option) any later version.
9+
**
10+
** This program is distributed in the hope that it will be useful,
11+
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
** GNU General Public License for more details.
14+
**
15+
** You should have received a copy of the GNU General Public License
16+
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#pragma once
20+
21+
#if defined(USING_STLPORT) || (defined(_MSC_VER) && _MSC_VER < 1300)
22+
/* 7.18.1.4 Integer types capable of holding object pointers */
23+
#ifdef _WIN64
24+
typedef __int64 intptr_t;
25+
typedef unsigned __int64 uintptr_t;
26+
#else
27+
typedef int intptr_t;
28+
typedef unsigned int uintptr_t;
29+
#endif
30+
31+
/* 7.18.1.1 Exact-width integer types */
32+
typedef signed char int8_t;
33+
typedef unsigned char uint8_t;
34+
typedef short int16_t;
35+
typedef unsigned short uint16_t;
36+
typedef int int32_t;
37+
typedef unsigned int uint32_t;
38+
typedef __int64 int64_t;
39+
typedef unsigned __int64 uint64_t;
40+
/* 7.18.1.2 Minimum-width integer types */
41+
typedef signed char int_least8_t;
42+
typedef unsigned char uint_least8_t;
43+
typedef short int_least16_t;
44+
typedef unsigned short uint_least16_t;
45+
typedef int int_least32_t;
46+
typedef unsigned uint_least32_t;
47+
typedef __int64 int_least64_t;
48+
typedef unsigned __int64 uint_least64_t;
49+
/* 7.18.1.3 Fastest minimum-width integer types
50+
* Not actually guaranteed to be fastest for all purposes
51+
* Here we use the exact-width types for 8 and 16-bit ints.
52+
*/
53+
typedef signed char int_fast8_t;
54+
typedef unsigned char uint_fast8_t;
55+
typedef short int_fast16_t;
56+
typedef unsigned short uint_fast16_t;
57+
typedef int int_fast32_t;
58+
typedef unsigned int uint_fast32_t;
59+
typedef __int64 int_fast64_t;
60+
typedef unsigned __int64 uint_fast64_t;
61+
/* 7.18.1.5 Greatest-width integer types */
62+
typedef __int64 intmax_t;
63+
typedef unsigned __int64 uintmax_t;
64+
/* 7.18.2 Limits of specified-width integer types */
65+
/* 7.18.2.1 Limits of exact-width integer types */
66+
#define INT8_MIN (-128)
67+
#define INT16_MIN (-32768)
68+
#define INT32_MIN (-2147483647 - 1)
69+
#define INT64_MIN (-9223372036854775807i64 - 1)
70+
#define INT8_MAX 127
71+
#define INT16_MAX 32767
72+
#define INT32_MAX 2147483647
73+
#define INT64_MAX 9223372036854775807i64
74+
#define UINT8_MAX 255
75+
#define UINT16_MAX 65535
76+
#define UINT32_MAX 0xffffffffU /* 4294967295U */
77+
#define UINT64_MAX 0xffffffffffffffffUi64 /* 18446744073709551615ULL */
78+
/* 7.18.2.2 Limits of minimum-width integer types */
79+
#define INT_LEAST8_MIN INT8_MIN
80+
#define INT_LEAST16_MIN INT16_MIN
81+
#define INT_LEAST32_MIN INT32_MIN
82+
#define INT_LEAST64_MIN INT64_MIN
83+
#define INT_LEAST8_MAX INT8_MAX
84+
#define INT_LEAST16_MAX INT16_MAX
85+
#define INT_LEAST32_MAX INT32_MAX
86+
#define INT_LEAST64_MAX INT64_MAX
87+
#define UINT_LEAST8_MAX UINT8_MAX
88+
#define UINT_LEAST16_MAX UINT16_MAX
89+
#define UINT_LEAST32_MAX UINT32_MAX
90+
#define UINT_LEAST64_MAX UINT64_MAX
91+
/* 7.18.2.3 Limits of fastest minimum-width integer types */
92+
#define INT_FAST8_MIN INT8_MIN
93+
#define INT_FAST16_MIN INT16_MIN
94+
#define INT_FAST32_MIN INT32_MIN
95+
#define INT_FAST64_MIN INT64_MIN
96+
#define INT_FAST8_MAX INT8_MAX
97+
#define INT_FAST16_MAX INT16_MAX
98+
#define INT_FAST32_MAX INT32_MAX
99+
#define INT_FAST64_MAX INT64_MAX
100+
#define UINT_FAST8_MAX UINT8_MAX
101+
#define UINT_FAST16_MAX UINT16_MAX
102+
#define UINT_FAST32_MAX UINT32_MAX
103+
#define UINT_FAST64_MAX UINT64_MAX
104+
/* 7.18.2.4 Limits of integer types capable of holding
105+
object pointers */
106+
#ifdef _WIN64
107+
#define INTPTR_MIN INT64_MIN
108+
#define INTPTR_MAX INT64_MAX
109+
#define UINTPTR_MAX UINT64_MAX
110+
#else
111+
#define INTPTR_MIN INT32_MIN
112+
#define INTPTR_MAX INT32_MAX
113+
#define UINTPTR_MAX UINT32_MAX
114+
#endif
115+
/* 7.18.2.5 Limits of greatest-width integer types */
116+
#define INTMAX_MIN INT64_MIN
117+
#define INTMAX_MAX INT64_MAX
118+
#define UINTMAX_MAX UINT64_MAX
119+
/* 7.18.3 Limits of other integer types */
120+
#ifdef _WIN64
121+
#define PTRDIFF_MIN INT64_MIN
122+
#define PTRDIFF_MAX INT64_MAX
123+
#else
124+
#define PTRDIFF_MIN INT32_MIN
125+
#define PTRDIFF_MAX INT32_MAX
126+
#endif
127+
#define SIG_ATOMIC_MIN INT32_MIN
128+
#define SIG_ATOMIC_MAX INT32_MAX
129+
#ifndef SIZE_MAX
130+
#ifdef _WIN64
131+
#define SIZE_MAX UINT64_MAX
132+
#else
133+
#define SIZE_MAX UINT32_MAX
134+
#endif
135+
#endif
136+
137+
#define WCHAR_MIN 0
138+
#define WCHAR_MAX ((wchar_t)-1)
139+
/*
140+
* wint_t is unsigned short for compatibility with MS runtime
141+
*/
142+
#define WINT_MIN 0U
143+
#define WINT_MAX 0xffffU
144+
/* 7.18.4 Macros for integer constants */
145+
/* 7.18.4.1 Macros for minimum-width integer constants
146+
Accoding to Douglas Gwyn <gwyn@arl.mil>:
147+
"This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
148+
9899:1999 as initially published, the expansion was required
149+
to be an integer constant of precisely matching type, which
150+
is impossible to accomplish for the shorter types on most
151+
platforms, because C99 provides no standard way to designate
152+
an integer constant with width less than that of type int.
153+
TC1 changed this to require just an integer constant
154+
*expression* with *promoted* type."
155+
The trick used here is from Clive D W Feather.
156+
*/
157+
#define INT8_C(val) (INT_LEAST8_MAX-INT_LEAST8_MAX+(val))
158+
#define INT16_C(val) (INT_LEAST16_MAX-INT_LEAST16_MAX+(val))
159+
#define INT32_C(val) (INT_LEAST32_MAX-INT_LEAST32_MAX+(val))
160+
/* The 'trick' doesn't work in C89 for long long because, without
161+
suffix, (val) will be evaluated as int, not intmax_t */
162+
#define INT64_C(val) val##i64
163+
#define UINT8_C(val) (val)
164+
#define UINT16_C(val) (val)
165+
#define UINT32_C(val) (val##i32)
166+
#define UINT64_C(val) val##ui64
167+
/* 7.18.4.2 Macros for greatest-width integer constants */
168+
#define INTMAX_C(val) val##i64
169+
#define UINTMAX_C(val) val##ui64
170+
171+
#else
172+
173+
#include <cstdint>
174+
175+
#endif

0 commit comments

Comments
 (0)