jsource
jsource copied to clipboard
Convert #DEFINE const numbers to variables and enums.
Might be a bit too early to do this.
- All .c extensions would need to be .cpp; or we can't use constexpr.
- These are just a few examples.
- Some of these could be enums instead of a static constexpr values.
- jc.h looks like it could definitely be an enum.
- Some of the values could be replaced with const values from the standard library. std::numeric_limits
555 hits in 46 files
regular expression pattern: integer
#define\s+([\d\w_]+)\s+(-?\s*\d+)\s*?(?=$|//|/\*)
matches
#define EVRANK -14
#define EVSPELL 16
#define EVSTACK 17 //blah
#define EVSTOP 18 /* blah
replace pattern
static int constexpr $1 = $2;
end result
static int constexpr EVRANK = -14;
static int constexpr EVSPELL = 16;
static int constexpr EVSTACK = 17; //blah
static int constexpr EVSTOP = 18; /* blah */
A basic enum creates something similar to above.
enum {
EVRANK = -14,
EVSPELL = 16,
EVSTACK = 17, //blah
EVSTOP = 18, /* blah */
}
Enum's can have names though in c all the members are global anyway. In c++ 11 we get scopes with enum class and set the base integral type. So in cases where we're defining a lot of constants maybe enums are better.
5 hits in 2 files
regular expression pattern: double
#define\s+([\d\w_]+)\s+(-?\s*\d+\.\d+)\s*?(?=$|//|/\*)
matches
#define EMAX 709.78271289338409
#define EMIN -744.44007192138126
#define EMAX2 710.47586007394398
#define TMAX 19.066172834610153
replace pattern
static double constexpr $1 = $2;
static double constexpr EMAX = 709.78271289338409;
static double constexpr EMIN = -744.44007192138126;
static double constexpr EMAX2 = 710.47586007394398;
static double constexpr TMAX = 19.066172834610153;