diasurgical / devilution

Diablo devolved - magic behind the 1996 computer game
Other
8.79k stars 920 forks source link

Suggestion to use WinAPI typedefs for signed integer types #444

Open 7keo opened 6 years ago

7keo commented 6 years ago

Currently winapi types are being used for mostly unsigned types (BYTE, WORD, DWORD). These are defined in WinDef.h, the project files also are including WinNT.h which defines the following types:

/* Define the basic types */
#ifndef VOID
#define VOID void
#endif
typedef VOID           *PVOID;
typedef VOID           *PVOID64;
typedef BYTE            BOOLEAN,    *PBOOLEAN;
typedef char            CHAR,       *PCHAR;
typedef short           SHORT,      *PSHORT;
#ifdef _MSC_VER
typedef long            LONG,       *PLONG;
#else
typedef int             LONG,       *PLONG;
#endif

(note the use of "BOOLEAN" for 8 bit unlike the 32 bit "BOOL")

and was probably available at the time at least of v1.09b.

This would read well along with, and be consistent with the unsigned types already in use.

edit: my suggestion also includes the use of "VOID".

AJenbo commented 6 years ago

BOOLEAN would explain some of the cases of 8bit value being used as a boolean and i think it better then using c++ bool.

mewmew commented 6 years ago

Candidates for BOOLEAN type based on their use:

The following have BOOL sometimes and BOOLEAN sometimes, it seems:

Candidates for BOOL type based on their use:

ghost commented 6 years ago

The only counter argument against BOOLEAN is that the PSX has a typedef for BOOL but not the former. It's also typdef'd as unsigned char/BYTE where as some cases used a signed char.

mewmew commented 6 years ago

The only counter argument against BOOLEAN is that the PSX has a typedef for BOOL but not the former. It's also typdef'd as unsigned char/BYTE where as some cases used a signed char.

While a valid counter argument, I think one reason that the PSX debug symbols don't have BOOLEAN is simply because there are no bits left to represent it. The SYM type representation uses all bits.

From https://github.com/sanctuary/sym/blob/master/type.go#L70

// Base types.
const (
    BaseNull   Base = 0x0 // NULL
    BaseVoid   Base = 0x1 // VOID
    BaseChar   Base = 0x2 // CHAR
    BaseShort  Base = 0x3 // SHORT
    BaseInt    Base = 0x4 // INT
    BaseLong   Base = 0x5 // LONG
    BaseFloat  Base = 0x6 // FLOAT
    BaseDouble Base = 0x7 // DOUBLE
    BaseStruct Base = 0x8 // STRUCT
    BaseUnion  Base = 0x9 // UNION
    BaseEnum   Base = 0xA // ENUM
    // Member of enum.
    BaseMOE    Base = 0xB // MOE
    BaseUChar  Base = 0xC // UCHAR
    BaseUShort Base = 0xD // USHORT
    BaseUInt   Base = 0xE // UINT
    BaseULong  Base = 0xF // ULONG
)

Therefore, I think we may still use BOOLEAN as some variables definitely have the bool characteristics.

ghost commented 6 years ago

But is there any base type for BOOL itself? It seems like a typdef 94 Def class TPDEF type UCHAR size 0 name BOOL Either way, I think we can still use BOOLEAN for convenience.

mewmew commented 6 years ago

But is there any base type for BOOL itself? It seems like a typdef

Oh, I guess you are right.

Either way, I think we can still use BOOLEAN for convenience.

I think so too.

AJenbo commented 6 years ago

Nice 😊

AJenbo commented 6 years ago

VOID is in the sym file, but I don't see what benefit it gives us since a lot of other values use lower case variants still?