Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Is this a correct print macro?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Joel C. Salomon, post: 4211436"] What do you mean by "ok"? It works, if that's what you mean. If you're using C99, you might also want to add __function__ to the debug output. Given the output format, each DEBUGPRINT belongs on its own output line -- so don't make the user include the newline. Also note that you cannot use this version without additional arguments; e.g., DEBUGPRINT("got here, no variables to display\n"); is invalid. Here's some code I've used to accomplish much the same idea: /* debug_print.h */ #ifndef DEBUG_PRINT_H #define DEBUG_PRINT_H extern void debug_print(char const *file, long line, char const *func, char const *fmt, ...); #define debug_print(...) \ debug_print(__FILE__, __LINE__, __func__, __VA_ARGS__) #endif /* end debug_print.h */ /* debug_print.c */ #include <stdio.h> #include <stdarg.h> #include "debug_print.h" #undef debug_print void debug_print(char const *file, long line, char const *func, char const *fmt, ...) { fprintf(stderr, "[%s:%ld, %s()] ", file, line, func); va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); fprintf(stderr, "\n"); } /* end debug_print.h */ (Actually, my code style include saving argv[0] in a global variable, and I include that as well.) Share & enjoy. --Joel [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Is this a correct print macro?
Top