Skip to content

Commit

Permalink
Fix MSVC issue with U_CX_LOG macros
Browse files Browse the repository at this point in the history
MSVC doesn't conform to the C standard when it comes to macro expansion:
https://stackoverflow.com/a/62364135

Therefore a workaround is now added to u_cx_log.h to make the U_CX_LOG
macros work for MSVC.

Starting from Visual Studio 2019 there is an option to enable preprocessor
conformity that would also solve the problem:
  /Zc:preprocessor
  • Loading branch information
antevir committed Feb 8, 2024
1 parent 1eebd7d commit dab249b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions inc/u_cx_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,19 @@
#endif

/* Internal defines - do not use! */
#define _U_CX_LOG_BEGIN_FMT(enabled, chText, format, ...) \
#define __U_CX_LOG_BEGIN_FMT(enabled, chText, format, ...) \
if (enabled && uCxLogIsEnabled()) { \
uCxLogPrintTime(); \
U_CX_PORT_PRINTF(chText " " format, ##__VA_ARGS__); \
}
#define _U_CX_LOG(enabled, chText, format, ...) \
#define __U_CX_LOG(enabled, chText, format, ...) \
if (enabled && uCxLogIsEnabled()) { \
U_CX_PORT_PRINTF(format, ##__VA_ARGS__); \
}
/* MSVC workaround */
#define EXPAND(x) x
#define _U_CX_LOG_BEGIN_FMT(...) EXPAND(__U_CX_LOG_BEGIN_FMT(__VA_ARGS__))
#define _U_CX_LOG(...) EXPAND(__U_CX_LOG(__VA_ARGS__))

/* ----------------------------------------------------------------
* TYPES
Expand Down

0 comments on commit dab249b

Please sign in to comment.