在我们的跨平台c项目中,我们使用宏来进行日志记录:
#if _WINDOWS
#define DEBUG_PRINTF(x) KdPrint(x)
#endif
DEBUG_PRINTF
用法示例:
DEBUG_PRINTF(("Message with param (%s)\n", pString)); // (1)
DEBUG_PRINTF(("Message with no param\n")); // (2)
没关系。根据{{3}},对KdPrint的调用需要双括号:
KdPrint (( Format, arguments ))
KdPrintEx (( DPFLTR_DEFAULT_ID, DPFLTR_INFO_LEVEL, Format, arguments ))
我的问题是如何通过在 userspace 中的其他平台(例如linux)上移植(1)
来处理已存在的宏,例如(2)
和DEBUG_PRINTF
?
例如定义
#if defined (__LINUX__)
#define DEBUG_PRINTF((x)) fprintf(stderr, x)
#endif
不会编译(1)
等宏。
答案 0 :(得分:2)
我会反过来这样做:
#if _WINDOWS
#define DEBUG_PRINTF(x) KdPrint((x))
#else
#define DEBUG_PRINTF(format, ...) fprintf(stderr, format, ##__VA_ARGS__)
#endif
用法:
DEBUG_PRINTF("Message with param (%s)\n", pString);