I have a debug system where I want to use a function with a code number to be printed in Terminal using printf
. Currently the function is like this:
#define DEBUG(args...) general_printf(CMT_Common_Debug,args)
void general_printf(int messageCat, __const char *__restrict __format, ...)
{
printf("[%d]",messageCat);
printf(__format);
}
So what this function does it to call a printf
preceded by a identifier code in the format [code_here]
. The problem I'm facing is that something might happen that makes some time pass between the two calls to printf
leading to a broken message in Terminal; this means I'll have to do a single call to printf
. Unfortunately joining both parts as the following didn't work:
printf("[%d]%s",messageCat,__format);
; the %d, %u and the like were not filled. And I wasn't able to find how could I pass the ...
to printf
.
I consulted another developer and he suggested somehow copying the data to a buffer, merging the two parts and then printing, but that would take too much processing; I'ld like a more straight forward method.
So how could I do this?
EDIT
My question isn't exactly unique compared to the possible duplicate case, but even if it is that thread doesn't give me the solution I need, namely, how to add the int messageCat
to the same call of printf
or similar function.