F
francesco
I'm programming an embedded system, on a Fujitsu microcontroller.
Stated that I'm not sure about constants optimization, I'm trying to
declare constants in two ways, one for debug version and one for
release version.
In debug, I would like to use const declaration, as I found it more
safer:
for example: const uint8_t SPEED_FAST = 10;
In release, I would like to use #define, as the constant value is
substituted inside the code, thus optimizing RAM usage:
for example: #define SPEED_FAST 10
I've written this macro:
#ifdef NDEBUG
#define constant(type, name, value) #define name value
#else
#define constant(type, name, value) const type name = value;
#endif /* NDEBUG */
Actually, this code doesn't work as in the NDEBUG version I read this
error:
Misplaced '#' or '##' in a macro definition.
How should I do?
Thanks.
Stated that I'm not sure about constants optimization, I'm trying to
declare constants in two ways, one for debug version and one for
release version.
In debug, I would like to use const declaration, as I found it more
safer:
for example: const uint8_t SPEED_FAST = 10;
In release, I would like to use #define, as the constant value is
substituted inside the code, thus optimizing RAM usage:
for example: #define SPEED_FAST 10
I've written this macro:
#ifdef NDEBUG
#define constant(type, name, value) #define name value
#else
#define constant(type, name, value) const type name = value;
#endif /* NDEBUG */
Actually, this code doesn't work as in the NDEBUG version I read this
error:
Misplaced '#' or '##' in a macro definition.
How should I do?
Thanks.