How do I implement no-op macro (or template) in C++?

后端 未结 9 1960
谎友^
谎友^ 2020-12-01 11:53

How do I implement no-op macro in C++?

#include    

#ifdef NOOP       
    #define conditional_noop(x) what goes here?   
#else       
    #         


        
9条回答
  •  盖世英雄少女心
    2020-12-01 12:57

    As this is a macro, you should also consider a case like

    if (other_cond)
        conditional_noop(123);
    

    to be on the safe side, you can give an empty statement like

    #define conditional_noop(X) {}
    

    for older C sometimes you need to define the empty statment this way (should also get optimized away):

    #define conditional_noop(X) do {} while(0)
    

提交回复
热议问题