P
pinkfloydhomer
I want to have debugging macro or function that I can use like:
DEBUG("bla bla bla %d bla %s bla bla %d %d", 1, "42", 3, 4);
just as with printf. I want to avoid implementing this functionality
myself with varargs etc.
Now, in my case, I cannot use printf etc to output with. I have to use
some other function that can only take a string. Let's call it
output(char* str). Today, when debugging, I insert something like:
{
char buffer[200];
sprintf(buffer, "bla bla bla %d bla %s bla bla %d %d", 1, "42", 3,
4);
output(buffer);
}
This is tedious. I want to just be able to do
DEBUG("bla bla bla %d bla %s bla bla %d %d", 1, "42", 3, 4);
or something similar. But I can't just make the above piece of code
into a macro. I thought about doing something like adding extra
parentheses like:
DEBUG(("bla bla bla %d bla %s bla bla %d %d", 1, "42", 3, 4));
so that the macro receives the entire parenthesis as one argument, but
then I can't just call sprintf with that argument...
How do I solve this problem?
/David
DEBUG("bla bla bla %d bla %s bla bla %d %d", 1, "42", 3, 4);
just as with printf. I want to avoid implementing this functionality
myself with varargs etc.
Now, in my case, I cannot use printf etc to output with. I have to use
some other function that can only take a string. Let's call it
output(char* str). Today, when debugging, I insert something like:
{
char buffer[200];
sprintf(buffer, "bla bla bla %d bla %s bla bla %d %d", 1, "42", 3,
4);
output(buffer);
}
This is tedious. I want to just be able to do
DEBUG("bla bla bla %d bla %s bla bla %d %d", 1, "42", 3, 4);
or something similar. But I can't just make the above piece of code
into a macro. I thought about doing something like adding extra
parentheses like:
DEBUG(("bla bla bla %d bla %s bla bla %d %d", 1, "42", 3, 4));
so that the macro receives the entire parenthesis as one argument, but
then I can't just call sprintf with that argument...
How do I solve this problem?
/David