Forward an invocation of a variadic function in C

前端 未结 12 2429
悲哀的现实
悲哀的现实 2020-11-22 06:41

In C, is it possible to forward the invocation of a variadic function? As in,

int my_printf(char *fmt, ...) {
    fprintf(stderr, \"Calling printf with fmt %         


        
12条回答
  •  孤独总比滥情好
    2020-11-22 07:17

    Use vfprintf:

    int my_printf(char *fmt, ...) {
        va_list va;
        int ret;
    
        va_start(va, fmt);
        ret = vfprintf(stderr, fmt, va);
        va_end(va);
        return ret;
    }
    

提交回复
热议问题