Populating a va_list

后端 未结 4 1046
花落未央
花落未央 2020-12-01 18:09

Is there a way to create a va_list from scratch? I\'m trying to call a function that takes a va_list as a parameter:

func(void **e         


        
4条回答
  •  攒了一身酷
    2020-12-01 18:29

    Your stupid_func is perfectly valid C code, otherwise how would you supposedly call vprintf and similar functions?

    The glib library make use of these wrappers extensively. The C99 specification itself has something similar in the examples. Excerpt from section 7.19.6.8:

    The following shows the use of the vfprintf function in a general error-reporting routine.

    #include 
    #include 
    void error(char *function_name, char *format, ...)
    {
        va_list args;
        va_start(args, format);
        // print out name of function causing error
        fprintf(stderr, "ERROR in %s: ", function_name);
        // print out remainder of message
        vfprintf(stderr, format, args);
        va_end(args)
    }
    

提交回复
热议问题