Error with #define?

This one has me stumped.
I use this construct in most of my projects:

//--------------- WiFi declarations ---------------
// WiFi declarations
#define SKETCH_NAME "motorControlV2"
#define SKETCH_VERSION "2.0"
#include <ESP8266WiFi.h>        // Not needed if also using the Arduino OTA Library...
#include <Kaywinnet.h>          // WiFi credentials
char macBuffer[24];             // Holds the last three digits of the MAC, in hex.
char hostName[24];              // Holds nodeName + the last three bytes of the MAC address.
#ifndef nodeName
char nodeName[] = SKETCH_NAME;                // Give this node a name
#endif

But for some reason that I can't find, I get an error. But only in this sketch.

motorControlV2:12:21: error: expected initializer before string constant
 #define SKETCH_NAME "motorControlV2"
                     ^

Can anyone see anything wrong?

If I add an empty setup and loop and comment out your library includes, I can compile it.

Try this:

#define SKETCH_NAME <motorControlV2>
#define SKETCH_VERSION <2.0>
#include <ESP8266WiFi.h>        // Not needed if also using the Arduino OTA Library...
#include <Kaywinnet.h>          // WiFi credentials
char macBuffer[24];             // Holds the last three digits of the MAC, in hex.
char hostName[24];              // Holds nodeName + the last three bytes of the MAC address.
#ifndef nodeName
char nodeName[] = SKETCH_NAME;                // Give this node a name
#endif

im not sure it works!

makes no sense what you wrote there

It says that the 3rd line of the fragment you posted is the 12th line of your sketch. What are the lines above the ones you posted?

Compiles fine for me:

//--------------- WiFi declarations ---------------
// WiFi declarations
#define SKETCH_NAME "motorControlV2"
#define SKETCH_VERSION "2.0"
// #include <ESP8266WiFi.h>        // Not needed if also using the Arduino OTA Library...
// #include <Kaywinnet.h>          // WiFi credentials
char macBuffer[24];             // Holds the last three digits of the MAC, in hex.
char hostName[24];              // Holds nodeName + the last three bytes of the MAC address.
#ifndef nodeName
char nodeName[] = SKETCH_NAME;                // Give this node a name
#endif
void setup() {}
void loop() {}

It compiles for me with the #include for Kaywinnet.h commented out and, of course, with the addition of a setup() and loop() function

I suspect that the #define has quotation marks in it and later it is printed inside quotation marks so you end up with two quotation marks

Comments.

But, I did accidentally find the cause.
About 20 lines down, I had a malformed #define line that I fiixed.

So, what should have been a redefinition error presented as an expected initializer before string constant error.

Now, I can't replicate the error......

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