The following example shows how a macro MyPrintf can be defined which is mapped to printf function call.
#define MyPrintf(fmt,args...) printf(fmt,args)
It is required to mask all debug messages for production builds. This can be achieved by using a macro that takes variable number of arguments. In such cases, the following can be done to enable or disable such messages at compile time using HAVE_DEBUG switch. One advantage of this method is that it will leave no print on the target binary when HAVE_DEBUG is not defined. In other words, if the HAVE_DEBUG compile-time switch is not defined, no strings passed to MyPrintf function will be present in the target binary.
#if defined(HAVE_DEBUG) #define MyPrintf(fmt,args...) printf(fmt,args) #else #define MyPrintf(fmt,args...) #endif
If you already have a file and want to turn of all printf messages in it, you can define the following macro in the beginning of the C file after all include files.
#define printf(fmt,args...)
This macro expands all occurrences of printf to a blank statement during pre-processing.