The dirtype enum has been driving me crazy in the process of porting WinROTT C code to C++. The C compiler allows variables of type dirtype to be used interchangably with int types. The C style enum is defined as:
typedef enum {
east,
northeast,
north,
northwest,
west,
southwest,
south,
southeast,
nodir
} dirtype;
// So with C, you are allowed to perform the following:
dirtype x;
int y = north;
x = y >> 1; // (result is northeast)
// In C++, you cannot assign or cast an integer type to a dirtype.
// I could have defined operator overloads for dirtype, but it was
// easier to work out a brute force translation until I get all the files
// moved over to C++.
// The fix is something like this:
switch (y >> 1)
{
case 0:
x = east;
break;
case 1:
x = northeast;
break;
case 2:
x = north;
break;
case 3:
x = northest;
break;
case 4:
x = west;
break;
case 5:
x = southwest;
break;
case 6:
x = south;
break;
case 7:
x = southeast;
break;
default:
x = east;
break;
}
Because of the mixed environment, it is difficult to modify enum so that it can interchange with an integer. What works for C doesn't work correctly for C++. I ended up redefining the direction enum to use #define. It proved to be the simplest fix. No complex macros, no worrying about c++ decoration.
#define east 0
#define northeast 1
#define north 2
#define northwest 3
#define west 4
#define southwest 5
#define south 6
#define southeast 7
#define nodir -99
typedef short dirtype;
This allows the same tokens to be used in both the C++ modules and the C modules. It also allows arithmetic on dirtype variables.
The code is compiling, but I have 86 unresolved symbol errors. These are caused by C++ decoration of names in most cases and should be easy to fix. Hopefully, I'll have something to release soon.