Have macro 'return' a value

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

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

    should work.

    Edit: ... in GCC.

提交回复
热议问题