Passing variable number of arguments around

前端 未结 11 833
我寻月下人不归
我寻月下人不归 2020-11-22 07:16

Say I have a C function which takes a variable number of arguments: How can I call another function which expects a variable number of arguments from inside of it, passing a

11条回答
  •  鱼传尺愫
    2020-11-22 07:33

    You can try macro also.

    #define NONE    0x00
    #define DBG     0x1F
    #define INFO    0x0F
    #define ERR     0x07
    #define EMR     0x03
    #define CRIT    0x01
    
    #define DEBUG_LEVEL ERR
    
    #define WHERESTR "[FILE : %s, FUNC : %s, LINE : %d]: "
    #define WHEREARG __FILE__,__func__,__LINE__
    #define DEBUG(...)  fprintf(stderr, __VA_ARGS__)
    #define DEBUG_PRINT(X, _fmt, ...)  if((DEBUG_LEVEL & X) == X) \
                                          DEBUG(WHERESTR _fmt, WHEREARG,__VA_ARGS__)
    
    int main()
    {
        int x=10;
        DEBUG_PRINT(DBG, "i am x %d\n", x);
        return 0;
    }
    

提交回复
热议问题