Hi All,
I'm writing a debug logging function and was wondering if there's any way to pass variable arguments straight to another function without touching them.
For example I want to do something like this:
This doesn't compile, but you can see the idea - passing the var args straight through the debugLog function to the printf function without having to touch them.
Any help or pointers would be much appreciated.
Thanks in advance.
I'm writing a debug logging function and was wondering if there's any way to pass variable arguments straight to another function without touching them.
For example I want to do something like this:
Code:
#include <stdio.h>
const int maxlevel = 3;
void debugLog(int debuglevel, char *msg, ...);
void main(){
debugLog(2, "should be printed%d", 5);
debugLog(5, "should not be printed%d", 8);
}
void debugLog(int debuglevel, char *msg, ...){
if(debuglevel < maxlevel){
printf(msg, ...);
}
}
This doesn't compile, but you can see the idea - passing the var args straight through the debugLog function to the printf function without having to touch them.
Any help or pointers would be much appreciated.
Thanks in advance.