小编pdb*_*dbj的帖子

测试空宏定义

我在tracing.hh中有一组调试宏.它是否生成代码和输出是由真实源代码中的宏标志控制的:

// File:  foo.cc
#define TRACING 0
#include "tracing.hh"
// Away we go . . .
TRACEF("debug message");
Run Code Online (Sandbox Code Playgroud)

标志TRACING应该有一个值; 我通常在0和1之间切换.

在tracing.h中,

  • #ifdef TRACING 会告诉我跟踪是定义的.
  • #if TRACING 控制功能宏的定义 TRACEF()

但是如果TRACING没有价值呢?然后#if TRACING产生一个错误:

In file included from foo.c:3:
tracing.hh:73:12: error: #if with no expression
Run Code Online (Sandbox Code Playgroud)

如何测试TRACING是否定义但没有价值?

preprocessor c-preprocessor

21
推荐指数
3
解决办法
5105
查看次数

标签 统计

c-preprocessor ×1

preprocessor ×1