I use the following preprocessor macros for this task (inside MACROS.h ):
#ifdef DEBUG #define DWRITE write(*,*) __FILE__,__LINE__, #define dwrite write(*,*) __FILE__,__LINE__, #else #define DWRITE ! #define dwrite ! #endif
In my code, I have the following header:
#define DEBUG #include "MACROS.h" ... dwrite 'An error occurred!'
This gives me the file and the line where the error occurred, and by commenting on the first line, I can easily enable or disable the message.
You can easily expand it to different levels of debugging and writing to files ...
source share