I’m fresh off the boat when it comes to C++. I learned C in high school and enjoyed it very much, but it’s been so long since I’ve done anything with it, I’ve become really rusty.
Partway through my fork of MokoiGaming’s Game Engine, I ran into a strange condition in an if-block that was comparing the last character of a string to ELIX_DIR_SSEPARATOR. Why would there be two Ss? Did I do something wrong while renaming functions and code blocks with search/replace?
Investigating further, I found this double definition in a header file:
#define ELIX_DIR_SEPARATOR "/"
#define ELIX_DIR_SSEPARATOR '/'
I looked at this, completely puzzled why something would be defined twice. I figured it had to do with the difference between the quotes, so I removed one of the definitions and replaced the few instances there were of the DIR_SS version in the code to the DIR_S version to see what it would do (gotta love that.)
After an hour or so getting into the intricacies of C++’s string comparison, char comparison, and char* comparison, I figured it was just better to have two definitions in my header like what was originally there instead of dynamically trying to cast depending on the situation.
Is that right, or wrong? I like to live by DRY programming if I can avoid it, but in this case, casting to char from char* and vise-versa just seemed like so much more work than one more line in my header.
What do you guys and gals think?