我们可以定义一个预处理器宏来根据计时器打印调试消息吗?

标签 c c-preprocessor

我想打印/记录一条调试消息,如果满足条件并且在特定时间间隔后,则必须打印调试消息。是否可以使计时器滴答声成为预处理器定义的一部分?

最佳答案

Is it possible to make timer ticks part of pre-processor defines?

当然是这样。

伪代码:

#define LOG_MESSAGE(args)      \
  if ( enoughTimeHasPassed() ) \
  {                            \  
     log_message(args);        \
  }

哪里

int enoughTimeHasPassed()
{
  // Return true/false based on whether enough time has passed
  // since the last call to the function.
}

void log_message(argtype args)
{
   // Implement the logic to log the message
}

关于我们可以定义一个预处理器宏来根据计时器打印调试消息吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40669908/

相关文章:

检查构造常量是否为#define'

c++ - 所有结构成员的预处理器批处理

c++ - 模板和#defines 的奇怪行为

C Printf 将 %p 作为 system()

c - C 中的大数

c - 如何在编译时检查标志的存在?

C预处理器展开顺序

c - 为 Linux 内核开发设置 Netbeans/Eclipse

c - sqlite3 C 用户定义的函数未被调用

c - scanf导致C程序崩溃