I am Rahul. We have a complete software written out (with n other shared libraries maintained by various other teams). The shared libraries are loaded at run time by the main executable depending upon what feature user wants to run. All across our code, we are using printf and fprintf to print messages on the screen for the user. Now, we are adding a Graphical interface to our software and require that all such messages are displayed in a separate window inside that Graphical interface (whenever user is running in Graphical mode, else messages should be printed to screen only). For this, we need to overload printf and fprintf in our code. We have a combination of C and C++ code, as well as due to vast code base distributed across teams, it is not possible to replace printf/fprintf in all the code with some other function. So, what we did, we defined our own printf and fprintf functions that look something as follows -
Expand|Select|Wrap|Line Numbers
- extern "C" int fprintf (FILE *__restrict __stream,
- __const char *__restrict __format, ...)
- {
- va_list args;
- va_start(args,__format);
- int return_status = 0;
- if (is_gui && (__stream == stdout || __stream == stderr)) {
- return_status = showMessageInGui(NULL, __format, args);
- }
- else {
- return_status = vfprintf(__stream, __format, args);
- }
- va_end(args);
- return return_status;
- }
Above code works fine for following fprintf calls (that pass variable argument list to fprintf) -
fprintf (stdout,"This is a variable argument message - %s\n", "Rahul Jain");
However, for following fprintf call (that is not taking any variable arguments), it seems fprintf from libgcc is getting picked up as then print comes on the screen instead of our Graphical interface window -
fprintf (stdout,"This is a variable argument message - Rahul Jain\n");
I am not sure why this is happening. Is fprintf implemented as macro, such that it is working for case1 and not for case2. Can anybody help.
I would be really greateful if someone can help me and reply as soon as possible, we have a hight priority delivery item and is very critical... Really appreciate your help guys.