Getting rid of Microsoft specific types
Defines and typedefs such as BOOL, CONST, UINT and DWORD are used pretty much everywhere in the codebase.
Most of these defines where introduced a long time ago (BOOL was added before bool was thrown into C++) and now, most of them are meaningless.
Nowadays, every decent compiler should support C++'s fundamental types without any problem.
Of course, DirectX types and some other funky types (HWND, HHOOK and so on) can't be replaced but there's no excuse for more common types I've pointed out earlier.
Pros
- Less error-prone (every Microsoft specific type names are upper case)
- Makes high-level parts of the engine less dependent on MSVC / Windows API
- Improves compile/runtime speed and makes debugging tasks easier (
BOOLis ainttypedef whereasboolis a true type) - Syntax highlighting / code readability is slightly improved; GitHub syntax highlighter (and probably many others) don't know about
BOOL,HANDLEorDWORDbut it does its job perfectly well on the standard types.
Cons
- Nothing. Really, I can't think of any drawbacks.
What to do?
There's nothing hard. We just need to search for these types and replace them by their standard equivalent. If you _really_ have to use a non-standard type in a piece of code, it should be better to keep this code 'away (i.e. not in a header nor in the middle of a high-level source file) To make things easier, here's a table with what should be considered for replacement and their equivalents.
| Microsoft types | Standard equivalents | stdint types |
|---|---|---|
INT8 |
signed char |
int8_t |
PINT8 |
signed char * |
int8_t * |
BYTE / UCHAR / UINT8 |
unsigned char |
uint8_t |
LPBYTE / PBYTE |
unsigned char * |
uint8_t * |
INT16 / SHORT |
signed short |
int16_t |
PINT16 / PSHORT |
signed short * |
int16_t * |
USHORT / WORD / UINT16 |
unsigned short |
uint16_t |
LPWORD / PWORD |
unsigned short * |
uint16_t * |
INT / INT32 / LONG / LONG32 |
signed int |
int32_t |
LPINT / PINT / LPLONG / PLONG / PINT32 /PLONG32 / PLONG |
signed int * |
int32_t * |
DWORD / DWORD32 / UINT / UINT32 / ULONG32 / ULONG |
unsigned int |
uint32_t |
LPDWORD / PDWORD / PDWORD32 |
unsigned int * |
uint32_t * |
INT64 / LONGLONG / LONG64 |
signed long long |
int64_t |
PINT64 / PLONG64 / PLONGLONG |
signed long long * |
int64_t * |
DWORDLONG / DWORD64 / QWORD / UINT64 / ULONGLONG / ULONG64 |
unsigned long long |
uint64_t |
INT_PTR / LONG_PTR |
N/A1 | intptr_t |
DWORD_PTR / UINT_PTR |
N/A1 | uintptr_t |
BOOL / BOOLEAN |
bool |
N/A |
LPBOOL / PBOOL / PBOOLEAN |
bool * |
N/A |
CCHAR / CHAR |
char |
N/A |
LPSTR / PCHAR |
char * |
N/A |
LPCSTR / PCSTR |
const char * |
N/A |
CONST |
const |
N/A |
FLOAT |
float |
N/A |
PFLOAT |
float * |
N/A |
VOID |
void |
N/A |
LPCVOID |
const void * |
N/A |
WCHAR |
wchar_t |
N/A |
LPWSTR / PWSTR / PWCHAR |
wchar_t * |
N/A |
LPCWSTR / PCWSTR |
const wchar_t * |
N/A |
1 - Representation of an integer type for pointer precision
- INT_PTR / LONG_PTR are mapped to a 32-bit signed integer on 32-bits systems and to a 64-bit signed integer on 64-bits systems.
- DWORD_PTR / UINT_PTR are mapped to a 32-bit unsigned integer on 32-bits systems and to a 64-bit unsigned integer on 64-bits systems.
It's clear that the easiest way to do that would be to use cstdint along with the standard types. Feel free to share anything, any ideas about all this.
That's why it's required by the conventions. Except that I intended to put these types to common engine header.
I've read those conventions but I just wanted to make things a bit more clear about the types already present in the repo. I know that cstdint is C++11 only but it's already present on MSVC and GCC. However, having these type defined in our own header would make them naturally portable (as long as everything is well done)
Hey guys, apologies for chiming in here - SpaceBrain, I've sent you an email on your account linked on GitHub - please let me know if it's not the correct email to contact you on!
'BOOL' is part of some API contracts, so must stay there since they are part of the ABI.
For non-ABI uses, BOOL should be replaced by "bool".