ESP8266 compiler issues using R() rawliteral within PROGMEM F()

The following code below taken from an answer provided elsewhere on this forum compiles OK when the target board is set to Arduino Uno (or any others from the Arduino AVR section of boards).

But fails to compile when target is set to LOLIN( WeMos) D1 R1 & mini (or any other from the ESP8266 Boards (2.7.4) section of boards) with the error that is pasted after the code.

Any tips, hints warmly welcome.

Ornea

This code compiles ok when board set to UNO but fails when board set to ESP8266

void setup() {
  Serial.begin(9600);

  Serial.println(F("Regular F macro"));

  Serial.println(F(R"(
  Hello world! It
  is nice to meet
  you.
  )"));

  Serial.println(F(
  R"(Some formatted text here
  makes life easy for HTML
  servers, for example.
  Unlimited quantity of anonymous strings.
  )"));

  Serial.println(F("David Prentice"));
}

void loop() {

}

Error Message

Arduino: 1.8.13 (Windows 7), Board: "WeMos D1 R1, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600"

sketch_feb19a:7:20: error: unterminated raw string

   Serial.println(F(R"(

sketch_feb19a:14:3: error: unterminated raw string

   R"(Some formatted text here

   ^

sketch_feb19a:18:3: error: macro "F" passed 2 arguments, but takes just 1

   )"));

   ^

exit status 1

unterminated raw string

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

My end game is to finally do something like this

    server.sendContent(F(R"(rawliteral
    <div id='main'>
    Temperature PID controller.&nbsp;

    ...
    rawliteral)"));

Does it compile without the R if you still split the text over multiple lines (and set for ESP8266)?

No, it fails to compile. I can split it over several lines if quote each line. That's want I currently do.

Using R - rawliteral would just make the code easier to manage and looks like it should work.

Ornea

If I understand you correctly, that suggest the problem is a limitation with the compiler for the ESP handling text split over multiple lines rather than anything to do with using R (raw literal), presumably the same happens if you miss the F as well as the R.

Do you mean like this. This does compile but uses more memory (as expected)

void setup() {
  Serial.begin(9600);

  Serial.println((
  R"(Some formatted text here
  makes life easy for HTML
  servers, for example.
  Unlimited quantity of anonymous strings.
  )"));
}

void loop() {

}

I would work on the principle that you have found a problem with the compiler ( unless there is a preprocessor that handles the F option). I don't know how you log a suspected compiler problem, but if you do know, then I think it would be worth doing.

As to how to work round the problem, I can't see any easy options, looks like you will have to go back to escaping individual characters (CR/LF) which makes the code look much messier and harder to follow.

This is bugging me slightly, so I have been thinking about it :o

Have you tried the normal ways for splitting a C string over multiple lines, using ether:

char *my_string = "Line 1 "
                  "Line 2";

or

char *my_string = "Line 1 \
                   Line 2";

Not sure how the R function would treat the \ though in the second case.

Yes, the normal ways for splitting a C string works ok.

The first method you cite is the one I currently use in a slightly different form.

This second method (below) uses additional memory. When it is loaded on the ESP8266 it looks like "Line 1 Line 2" with spaces embedded.

char *my_string = "Line 1 \
                   Line 2";

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