I am currently developing a program that I intend to be portable. I have access to both Windows and macOS, and I would like to be able to debug easily on both. When error handling, I want to have debug breaks in there to make it easy(__debugbreak()
for MSVC). Since I intend to develop and test on multiple platforms, I would like to make a macro to do something like this:
#define DEBUG_BREAK #ifdef DEBUG\
#if _MSC_VER \
__debugbreak(); \
#elif __GNUC__ \
__builtin_trap(); \
#endif \
#endif
So I can write DEBUG_BREAK
anywhere I want to break code when debugging on any platform. When I use this macro, I get the error '#' not expected here
.
I found two somewhat related questions:
But neither of them answered my question, as they were trying to accomplish different things.
So my question is: How can I have preprocessor if statements inside of a macro if that is allowed? If it isn't possible, what can I do to get the same functionality this broken DEBUG_BREAK
macro is trying to do?
Note: DEBUG
is defined when compiling for debugging; it is not defined when compiling for release.