c++ macros with memory?

后端 未结 4 1402
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 16:48

    Not what you are actually asking for, but if WRITE_FOO was a definition you could get something similar (without context I will just reuse the names, even if they are not so clear on the intent):

    #define READ_FOO() WRITE_FOO
    
    #define WRITE_FOO hello
    code...[1]
    READ_FOO();
    code...[2]
    #define WRITE_ROO world
    code...[3]
    READ_FOO();
    
    // will expand to:
    code...[1]
    hello;
    code...[2]
    code...[3]
    world;
    

提交回复
热议问题