Imagine that I want a #define macro to be equal to the current value of another macro (if such a concept exists).
For instance:
#include "def_a.h"
This defines B as A If A later changes the definition (i.e., by redefinition), the value of B also changes (because B expands to A at the point of use, which further expands to the new value of A ).
What I would like is a way to “bake” the value of A in B so that B simply expands to the value of A , not A
For instance:
#define A first #define B BAKE_IN(A) #undef A #define A second #define C BAKE_IN(A) #undef A #define A third
Of course, BAKE_IN is not a real thing, but I wonder if there is a way to achieve this effect.
Now I really didn’t say what should happen if A itself is defined in terms of other macros, but I am fine with both “one level of extension” (ie B gets the value A, therefore additional macros are saved), as well as “full expansion "(i.e., A expands completely, recursively, as it would be at the point of use).
source share