OpenTrespasser / JurassicParkTrespasser

A git-based fork of the Jurassic Park: Trespasser source code.
99 stars 24 forks source link

Get rid of Microsoft specific types #3

Open GamerDude27 opened 5 years ago

GamerDude27 commented 5 years ago

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

#

Cons


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 equivalent 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

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.