0

Currently using to show debug output when in debug mode:

#ifdef _DEBUG
#define printX(...) Serial.printf( __VA_ARGS__ )
#else
#define printX(...) NULL
#endif 

yet this still include the printX in the result code, and the parameters which have been applied still consume memory, cpu power, and stack size, so my question is:

  • is there a way to have a macro, which is not including the function, and "ignoring" all of it's calls in the source when in "release mode" and basically not compile anything with it ?
Yordan Yanakiev
  • 2,546
  • 3
  • 39
  • 88

3 Answers3

2

A macro is a not a function. It does not consume any memory, cpu power, or stack size. This is because macros operate entirely at compile time, and just act as a text replacing mechanism. When the program is run, there are no macros which are "called".

SomeProgrammer
  • 1,134
  • 1
  • 6
  • 12
1

In my programs I include a line that says:

#define DEBUG_MODE

and I use it anywhere I want to compile with (or without) debug mode:

#ifdef DEBUG_MODE
    print here all the info I need for debug and certainly don't want in released binary.
#endif

Before releasing the final binary I comment out the definition line.

Nino
  • 702
  • 2
  • 6
  • 12
1

The macro

#define printX(...) NULL

replaces printX function call with all its arguments with plain NULL. This is a textual replacement that happens before a compiler is able to take a look at the code, so any nested calls inside printX, e.g.

printX(someExpensiveCall())

will also be completely eliminated.

Evg
  • 25,259
  • 5
  • 41
  • 83