Have macro 'return' a value

后端 未结 9 1874
闹比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:41

    For a macro to "return a value", the macro itself has to be an expression. Your macro is a statement block, which cannot evaluate to an expression.

    You really ought to write an inline function. It will be just as fast and far more maintainable.

提交回复
热议问题