JurassicParkTrespasser icon indicating copy to clipboard operation
JurassicParkTrespasser copied to clipboard

Get rid of Microsoft specific types

Open GamerDude27 opened this issue 6 years ago • 0 comments

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 (BOOL is a int typedef whereas bool is a true type)
  • Syntax highlighting / code readability is slightly improved; GitHub syntax highlighter (and probably many others) don't know about BOOL, HANDLE or DWORD but 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 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
  • 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.

GamerDude27 avatar Jan 30 '19 05:01 GamerDude27