I want to redefine the value of a macro constant on a certain condition in my C source code. I don´t be able to use conditional preprocessing directives for defining LEN_OSG because whether it is redefined with a another value or not is decided at run-time.
What I already have is:
if(condition) // proof condition for replacing the value in LEN_OSG.
{
if(LEN_OSG != CBS_LEN) // check if LEN_OS already has the value in CBS_LEN.
{
#undef LEN_OSG // undefine macro LEN_OSG by using `#undef` directive.
#define LEN_OSG CBS_LEN // recreate the macro LEN_OSG with new value.
}
}
Does the C syntax allow another way to abbreviate this instead of to using the #undef directive and thereafter recreating the macro with a new value by another #define directive (in just a single line)?
Desired solution would be something like that:
if(LEN_OSG != CBS_LEN) // check if LEN_OS already has the value in CBS_LEN.
{
#redefine LEN_OSG CBS_LEN // redefine LEN_OS with another value in one line.
}
#define,#if, ...) have disappeared when the compiler itself starts to run.ifs are evaluated at run-time by your program and the target's processor, but the preprocessor lines are evaluated at compile-time by the compiler and the host's processor. -- What do you really want to achieve? Please show us a minimal reproducible example.#errordirective, thus proving that some traditional compilation is performed before phase 4 (preprocessing) is complete.#undefand#define.