Have macro 'return' a value

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

    If you really want to do this, get a compiler that supports C++0x style lambdas:

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

    Although since CStrNullLastNL is basically a function you should probably rewrite it as a function.

提交回复
热议问题