//I wrote simple program to test debug macros, but it gives me compilation error
//Program:
#include <Arduino.h>
#define DEBUG
#ifdef DEBUG
#define DPRINT(...) Serial.print(__VA_ARGS__)
#define DPRINTLN(...) Serial.println(__VA_ARGS__)
#else
// define blank line
#define DPRINT(...)
#define DPRINTLN(...)
#endif
void setup() {
// put your setup code here, to run once:
String str ="Hello MrNams";
DPRINT("Here is my string %s",str);
}
void loop() {
// put your main code here, to run repeatedly:
}
//Compilation Error:
src/main.cpp: In function 'void setup()':
src/main.cpp:7:50: error: no matching function for call to 'HardwareSerial::print(const char [21], String&)' #define DPRINT(...) Serial.print(VA_ARGS)
^
src/main.cpp:19:3: note: in expansion of macro 'DPRINT'
DPRINT("Here is my string %s",str);
^~~~~~
In file included from C:/Users//.platformio/packages/framework-arduinoespressif32/cores/esp32/Stream.h:26,
from C:/Users//.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:177,
from src/main.cpp:2:
C:/Users//.platformio/packages/framework-arduinoespressif32/cores/esp32/Print.h:81:12: note: candidate: 'size_t Print::print(const __FlashStringHelper*)'
size_t print(const __FlashStringHelper *);
^~~~~
C:/Users//.platformio/packages/framework-arduinoespressif32/cores/esp32/Print.h:81:12: note: candidate expects 1 argument, 2 provided
C:/Users//.platformio/packages/framework-arduinoespressif32/cores/esp32/Print.h:82:12: note: candidate: 'size_t Print::print(const String&)'
size_t print(const String &);
#include <Arduino.h>
#define DEBUG
#ifdef DEBUG
#define DPRINT(...) Serial.print(__VA_ARGS__)
#define DPRINTLN(...) Serial.println(__VA_ARGS__)
#else
// define blank line
#define DPRINT(...)
#define DPRINTLN(...)
#endif
void setup()
{
Serial.begin(9600);
// put your setup code here, to run once:
String str = "Hello MrNams";
DPRINT("Here is my string ");
DPRINTLN(str);
}
void loop()
{
// put your main code here, to run repeatedly:
}
Same error, so issue is not MACRO expansion.
one thing is that it was working well, before i make it bit complicated like added firebase library for esp32, software serial library and it started failing.
The normal Serial.print() function only accepts a single argument (and occasionally a modifier.) You can do Serial.print(myNumber, HEX), but not Serial.print("Numer is", myNumber)
Serial.printf() (already mentioned) behaves more like the traditional C printf()