user2531608 user2531608 - 17 days ago 6
C Question

Can we define a pre-processor macro which prints debug messages based on timer?

I want to print/log a debug message which has to print debug message if condition met and if after specific interval. Is it possible to make timer ticks part of pre-processor defines?

Answer

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

Sure it is.

Psuedocode:

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

where

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
}
Comments