I have a project in which there are many names that, at the moment are hardcoded. The project is 2/5th C, 2/5th Python and 1/5th Python C-extension code.
I would like to "define" a lot of names for the project. I was thinking in two general formats:
// global.h
static const char[] FIELD_NAME = "__random_fields";
static const char[] DETERMINISTIC_NAME = "__non_random_fields";
static const uint32_t THISTHAT = 0x234;
static const float VERSION = 24.5;
for the C, and for the Python:
# global.py
FIELD_NAME = '__random_fields'
DETERMINISTIC_NAME = '__non_random_fields'
THISTHAT = 0x234
VERSION = 24.5
I would prefer to use static const
instead of #define
(for the C code), but it is only a personal preference in this project.
One option is to use a intermediate representation and add some script magic make-time parsing to generate both .h
and .py
. Would that be reinventing the wheel? Are there some general strategies or tips for achieving this? There is some Java in the project, so using .properties
would be ok, but... the problem persists, I need to do some magic conversion between formats.