c++ macros with memory?

后端 未结 4 1405
Happy的楠姐
Happy的楠姐 2020-12-10 16:32

Is it possible to define macros

write_foo(A);
and
read_foo();

so that:

WRITE_FOO(hello);

code_block_1;

READ_FOO();

code         


        
4条回答
  •  轮回少年
    2020-12-10 17:04

    Macros cannot redefine other macros, but you can do it manually.

    #define FOO hello
    
    FOO // expands to hello
    
    #undef FOO
    #define FOO world
    
    FOO // expands to world
    
    #undef FOO
    #define FOO blah
    
    FOO // expands to blah
    

    Unfortunately, the #define + #undef combination cannot be encapsulated in any other structure that I am aware of.

提交回复
热议问题