Have macro 'return' a value

后端 未结 9 1870
闹比i
闹比i 2021-01-31 10:12

I\'m using a macro and I think it works fine -

#define CStrNullLastNL(str) {char* nl=strrchr(str,\'\\n\'); if(nl){*nl=0;}}

So it works to zero out the last

9条回答
  •  佛祖请我去吃肉
    2021-01-31 10:44

    Can you use the comma operator? Simplified example:

    #define SomeMacro(A) ( DoWork(A), Permute(A) )
    

    Here B=SomeMacro(A) "returns" the result of Permute(A) and assigns it to "B".

提交回复
热议问题