I am developing an embedded application in C99, and the project contains some integer constants, defined as:
#define LEVEL1 0x0000
#define LEVEL2 (LEVEL1 + 1)
Since then, it has become useful to keep track of these values โโfor logging purposes, so I would like to use a macro to create a string literal from the evaluated versions above. For instance:
strncpy(str, STRING(LEVEL2), len);
perfect for
strncpy(str, "0x0001", len);
or even
strncpy(str, "0001", len);
Using a two-step macro with the # operator (as suggested by this question ) almost works. He appreciates
strncpy(str, "(LEVEL1 + 1)", len);
I would like to avoid using the runtime function - hence my attempt to solve macros. Suggestions?
source
share