Grazie mipadi, ho migliorato anche il tuo DEBUG_PRINT con le informazioni del file.
#define DEBUG 3
#if defined(DEBUG) && DEBUG > 0
#define DEBUG_PRINT(fmt, args...) fprintf(stderr, "DEBUG: %s:%d:%s(): " fmt, \
__FILE__, __LINE__, __func__, ##args)
#else
#define DEBUG_PRINT(fmt, args...) /* Don't do anything in release builds */
#endif
Testato con l'ultimo clang, ad es.
int main(int argc, char **args) {
DEBUG_PRINT("Debugging is enabled.\n");
DEBUG_PRINT("Debug level: %d", (int) DEBUG);
}
uscite:
DEBUG: debug.c:13:main(): Debugging is enabled.
DEBUG: debug.c:14:main(): Debug level: 3
fonte
2014-12-08 04:32:42
Dupe di http://stackoverflow.com/questions/1644868/c-define-macro-for-debug-printing tra molti altri. –
è stato richiesto prima; link alle mie risposte: http://stackoverflow.com/questions/1644868/c-define-macro-for-debug-printing/1645152#1645152 – Christoph