If you use C ++, you might be interested in my portable TRACE macro.
#ifdef ENABLE_TRACE # ifdef _MSC_VER # include <windows.h> # include <sstream> # define TRACE(x) \ do { std::ostringstream s; s << x; \ OutputDebugString(s.str().c_str()); \ } while(0) # else # include <iostream> # define TRACE(x) std::cerr << x << std::flush # endif #else # define TRACE(x) #endif
Example:
#define ENABLE_TRACE //can depend on _DEBUG or NDEBUG macros #include "my_above_trace_header.h" int main (void) { int i = 123; double d = 456.789; TRACE ("main() i="<< i <<" d="<< d <<'\n'); }
Any improvements / suggestions / contributions are welcome; -)
oliber
source share