Definition of macro printf in epicsStdio.h breaks C++ code
Affects | Status | Importance | Assigned to | Milestone | ||
---|---|---|---|---|---|---|
EPICS Base | Status tracked in 7.0 | |||||
3.15 |
Fix Released
|
Low
|
Ralph Lange | |||
3.16 |
Fix Released
|
Low
|
Unassigned | |||
7.0 |
Fix Released
|
Low
|
Unassigned |
Bug Description
In recent EPICS releases (3.16 and 7.0), the following preprocessor macro definition can be found in epicsStdio.h:
#ifdef printf
# undef printf
#endif /* printf */
#define printf epicsStdoutPrintf
This is very problematic for C++ code, because it will break valid code. Consider the following example:
#include <cstdio>
#include <epicsStdio.h>
void foo() {
std::
}
This code will not compile because printf is going to be replaced by epicsStdoutPrintf, thus resulting in a function call to std::epicsStdou
So far, the best idea for fixing this problem that I have come up with is not defining this macro when the header is included from C++ code, but maybe someone has a better idea.
Core Group review at ESS:
In the epicsStdio.h file, conditional on C++, define std::epicsStdou tPrintf( ) and friends as static inline functions that call ::epicsStdoutPr intf().
Who: TBD.