Add DEBUG_LOG_MSG macro
For printing logs only when DEBUG macro is turned on (without sprinkling idefs all around the code).
This commit is contained in:
parent
86d6647b4e
commit
b6959e2e4c
1 changed files with 30 additions and 1 deletions
|
@ -18,6 +18,9 @@
|
|||
|
||||
#ifndef DOSBOX_LOGGING_H
|
||||
#define DOSBOX_LOGGING_H
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
enum LOG_TYPES {
|
||||
LOG_ALL,
|
||||
LOG_VGA, LOG_VGAGFX,LOG_VGAMISC,LOG_INT10,
|
||||
|
@ -86,5 +89,31 @@ void GFX_ShowMsg(char const* format,...) GCC_ATTRIBUTE(__format__(__printf__, 1,
|
|||
|
||||
#endif //C_DEBUG
|
||||
|
||||
#ifdef NDEBUG
|
||||
// DEBUG_LOG_MSG exists only for messages useful during development, and not to
|
||||
// be redirected into internal DOSBox debugger for DOS programs (C_DEBUG feature).
|
||||
#define DEBUG_LOG_MSG(...)
|
||||
#else
|
||||
// There's no portable way to expand variadic macro using C99/C++11 (or older)
|
||||
// alone. This language limitation got removed only with C++20 (through addition
|
||||
// of __VA_OPT__ macro).
|
||||
#ifdef _MSC_VER
|
||||
#define DEBUG_LOG_MSG(fmt, ...) fprintf(stderr, fmt "\n", __VA_ARGS__)
|
||||
// ~
|
||||
// MSVC silently eliminates trailing comma if needed: ^
|
||||
#else
|
||||
#define DEBUG_LOG_MSG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
|
||||
// ~~~~~~~~~~~~~
|
||||
// ^
|
||||
// GCC and Clang provide '##' token as a language extension to explicitly remove
|
||||
// trailing comma when there's no trailing parameters.
|
||||
#endif
|
||||
// If it'll ever be necessary to support another compiler, which does not
|
||||
// support C++20 nor GNU extension nor MSVC extension, then behaviour can be
|
||||
// simulated by implementing C++ variadic template wrapped inside a macro
|
||||
// (at the cost of slowing down compilation).
|
||||
//
|
||||
// Another option it to use vsnprintf (at the cost of slowing down runtime).
|
||||
#endif // NDEBUG
|
||||
|
||||
#endif //DOSBOX_LOGGING_H
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue