c - Can I use two level of variable length argument functions...? -


i have 1 problem variable length argument debug log print function. simulate code here.

void secondprint(int level, const char* format,...) {    //printing log here    va_list arg;    va_start(arg, format);    vprintf(format, arg);    va_end(arg);    }  void firstprint(int level, const char* format,...) {    secondprint(level,format); }  void main() {    int level = 100;    firstprintf("log level = %d message = %s \n",level,"error message"); } 

"secondprint" supposed print "100 error message" expected, not printing printing " error message".

i not getting whats wrong one. suspecting way of calling "secondprint" "firstprint" function. firstprint receiving remaining arguments through ... invoking secondprint level , format arguments.

i can't use secondprint main directly. i have use firstprint , firstprint has call secondprint print log. how can achieve one.. thought use va_args macro definitions not in function definition.

and 1 more thing i can't *#define firstprint(a,b,...) secondprint(a,b,...)*

any highly appreciated in advance.

c varargs not designed passed more 1 level; kind of necessary stack manipulation required deep language. typically, in case this, have version of secondprint analagous vprintf -- secondprintv or similar, , have firstprint invoke secondprintv after extracting varargs, rather invoking secondprint directly (and, consistency, have secondprint invoke secondprintv internally).


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

javascript - Preserving URL fragment through CAS sign-on -

asp.net mvc - Implementing normal user/pass, Twitter & Facebook auth -