c preprocessor - How to store a macro in another macro? -
i have macro ddlogdebug(...)
, following
#define _ddlogdebug(arg...) ddlogdebug(args) #undef ddlogdebug #define ddlogdebug(args...) dosomething(); _ddlogdebug(arg...)
but not work. instead of #define _ddlogdebug(arg...) ddlogdebug(args)
, need command "stores" content of macro ddlogdebug
_ddlogdebug
.
does exist?
how should 1 when 1 wants modify macro definition not exposed?
you can't purely standard preprocessor.
the reason macro definition doesn't work e.g. function definition in main language: @ time when define _ddlogdebug
, isn't linking definition of ddlogdebug
- it's storing exactly wrote. won't attempt find expansion names until macro being used in program outside of definitions. point, definition ddlogdebug
gone.
this valuable , intended behaviour, because allows use of techniques x-macros: 1 definition can provide framework , let different calling contexts decide how use in different ways. not outer macro not dependent on definitions available @ time written, meaning of contents can change throughout program without having change structure.
if can't work around problem, might have luck non-standard widely-supported push_macro
, pop_macro
directives.
example of use of push , pop:
#define foo 123 #pragma push_macro("foo") #undef foo foo #pragma pop_macro("foo") foo
run through gcc -e
, you'll see emits foo
(newline) 123
. works clang.
Comments
Post a Comment