_DEBUG__ directive question

I recently came across this line of code , which someone sent:

#define _DEBUG_ //This allows debug logging over the serial port.

It spits out debug info on the serial port - am curious since I have not seen this before.
I am using a MKR GSM 1400 - connecting to Thinger.io
Where can I read more about this?
thanks
Russell

All that line does is to define a macro named DEBUG

Later in the code you can test whether it is defined and take action depending on the test

#define _DEBUG_

void setup()
{
  Serial.begin(115200);
  while (!Serial);
#ifdef _DEBUG_
  Serial.println("_DEBUG_ is defined");
#endif
}

void loop()
{
}

It provides a mechanism for turning debugging output on and off by changing one line of code
Note that the macro might as well be named FRED for all the difference that it makes

To read more about such things take a look at C Preprocessor Directives - C and C++ Syntax Reference - Cprogramming.com and hundreds of other sites on the Web

Thanks for that - will check that out
[edit] - I can't see where the macro is defined anywhere in the code.
I added it to my MKR code and it also works. I think the macro is defined in the ThingerMKRGSM library

Rascalsailor:
I can't see where the macro is defined anywhere in the code.

Its defined here:

Rascalsailor:
I recently came across this line of code , which someone sent:

#define _DEBUG_ //This allows debug logging over the serial port.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.