int debug_enabled(void);

debug_enabled returns non-zero if the debugger is connected - you can use this to test if a debug input/output functions will work. For this to work correctly, the Startup Completion Breakpoint project property needs to be set to a point in the program where the startup code has finished initialising, this is typically main.