I am working on a project where the only debugging tool I have is the use of printf's embedded within my program. To turn this off for release I have written a function which calls the printf function and I am using a #define/#undef.
This works, but it would be easier if I could somehow embedded __FILE__ and __LINE__ in the dbprintf function. However if I replace:
printf( "%s", St );
in the dbprintf function with:
printf( "%s %d %s", __FILE__, __LINE__, St );
I get the filename and line number of the printf statement in the dbprint function, when I want the filename and line number of the statement calling the dbprintf function.
I would like for the dbprintf function to support multiple parameters just as printf does (i.e.):
dbprintf( "\nGot this far, A = %d.", A);
Any suggestions?
Note: The project is actually in C not C++. So any C++ solutions will not be much help.
That's not possible. __LINE__ and __FILE__ aren't real variables. When you compile your program they are just replaced by the line and file they are in. You have to pass them as arguments.
I was thinking that there maybe a way to replace the function with a macro, but I don't know how (if it is even possible) to create a macro that would accept an unspecified number of arguements.