Weird bug in C++: Macros definition for logging
I have created several macroses for easy logging.
The first 2 work fine. The third brings up a compile error, saying that there should be one more parentheses ')' before ';" when calling the macro.
Note: The last two lines are used to call the "LOG_WTS2" macro without and with extra parameters. If I write the code properly, the compiler tells me to put another ')' before ';' at the end of these two lines. When I put the extra ')' for each line, the code is compiled and the log is projected correctly to the screen. It seems like an issue within the definition of macros "LOG_WTS2". What is wrong with the code and how can it be fixed?
After redefining "LOG_WTF" with the same input as "LOG_WTS", there were no problems with compilation when using the correct syntax, without the extra parentheses ')'.
When calling "LOG_WTS" from another macro, the compiler still demands using an extra parentheses at the end of macro call:
If you look at the WTS macro, the one that calls AddOnScreenDebugMessage, at the end the first closing ) closes the inner Printf
the second ) closes the outer Printf
which means you never closed the actual function call to AddOnScreenDebugMessage. You need a third ) at the end of that macro to match.
answered Dec 06 '18 at 05:10 PM
Brian Johnstone STAFF
Follow this question
Once you sign in you will be able to subscribe for any updates here