I
I
Igor2019-05-26 17:55:40
Arduino
Igor, 2019-05-26 17:55:40

Will this code be used when compiling?

Good afternoon!
I have defined such a macro in my code, which is enabled with the flag DEBUG:

#ifdef DEBUG
#define debug(n) Serial.println("***"+String(n)+"***")
#else
#define debug(n) NULL;
#endif

Recently I wondered if this line of code would somehow compile, or be replaced by NULL;? I mean will it be called Stringat all?
debug(
      "New parameters was applied:\n\tfrequency = " +
      String(freq) +
      "\n\t duty = " +
      String(duty)
    );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Shatunov, 2019-05-26
@Igorello74

The preprocessor works at the 4th stage of code translation.
The preprocessor operates directly on the strings of the translation module in the form of memory blocks.
The description of your macro shows that although debugit takes an argument, it does not operate with this argument outside the debug configuration. Anywhere in the call to your macro, a substitution will occur NULLinstead of the entire call.
In fact, you do NULLn't even need this one as a substitution. Why do you need an abundance of hanging ones in the program code NULL? If you describe the macro like this:

#ifdef DEBUG
#define debug(n) Serial.println("***"+String(n)+"***")
#else
#define debug(n)
#endif

then the preprocessor will simply overwrite the macro call line.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question