tags:

views:

35

answers:

1

In .NET I would use System.Diagnostics.Trace...

What would I use in C or C++ ?

right now I have a macro defined:

diagnostics ON:

#define DIAG(A) { printf(A); }

debugging off:

#define DIAG(A) { if(FALSE) {}}

Is there a standard way?

+1  A: 

It depends on your environment. In Windows, I'd just use OutputDebugString. There's more complicated and configurable ways, but I've never needed it myself.

Not sure if there's a standard on *nix, though. The relatively few times I've written *nix C code, I use a DEBUG envvar and printf.

Mark Brackett
On unix, you just have to use stderr. Use `cerr << A` instead of `printf(A)`. As a bonus, this is type safe.
Vlad