gpt4 book ai didi

c - 跨平台项目中调试宏定义

转载 作者:行者123 更新时间:2023-11-30 14:25:46 25 4
gpt4 key购买 nike

在我们的跨平台 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)

没关系。根据KdPrint function reference对 KdPrint 的调用需要双括号:

KdPrint (( Format, arguments ))
KdPrintEx (( DPFLTR_DEFAULT_ID, DPFLTR_INFO_LEVEL, Format, arguments ))

我的问题是如何通过在其他平台上移植DEBUG_PRINTF来处理已经存在的宏,例如(1)(2)比如用户空间中的linux?

例如定义

#if defined (__LINUX__)
#define DEBUG_PRINTF((x)) fprintf(stderr, x)
#endif

不编译诸如(1)之类的宏。

最佳答案

我会反过来做:

#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);

关于c - 跨平台项目中调试宏定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9989808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com