Have macro 'return' a value

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

    to return value from macro:

    bool my_function(int a) {
        if (a > 100)return true;
        return false;
    }
    bool val = my_function(200);
    
    #define my_macro(ret_val,a){\
        if(a > 100 ) ret_val = true;\
        ret_val = false;\
    }
    bool val; my_macro(val, 200);
    

提交回复
热议问题