Compiler double slash issue (e.g. http://) using R() rawliteral within PROGMEM F()

ArduinoIDE 1.8.19 with ESP82666.

Hi,

Adding or removing double forward slash within R() statement makes that the program compiles and runs or fails to compile.

to summarize, in this case the program compiles and runs.

const char index_html[] PROGMEM = R"rawliteral(
....
xhr.open("GET", "/millis", true);
...
)rawliteral";

While with the following it won't compile.

const char index_html[] PROGMEM = R"rawliteral(
....
xhr.open("GET", "http:**//**192.168.1.49/millis", true);
...
)rawliteral";

Is it a bug with Rawliteral or double slashes // are forbidden?

Maybe someone else can also try adding or removing double slashes to see the effect on the compiler.

Thanks

P.S.

Please post the entire error message using copy and paste. I guess you know, '//' is a comment prefix.

I found that the raw string C++ syntax starts with R"( and ends in )". Or with a single character delimiter § (almost any char) it starts with R"§( and ends with )§". There may be a bug in the (undocumented?) rawliteral macro. Try again without rawliteral.

Why do you use raw strings at all? Inside double quotes only backslashes have a special meaning. I cannot find any backslashes in your code snippets.

Uh... Isn't an unescaped double-quote treated as the end of a double-quoted string? I see four double-quotes inside the raw string.

I get no error compiling this for "Generic ESP8266 Module" or "Arduino UNO".

const char index_html[] PROGMEM = R"rawliteral(
....
xhr.open("GET", "http://192.168.1.49/millis", true);
...
)rawliteral";

void setup() 
{
  Serial.begin(115200);
  delay(200);
  Serial.println((__FlashStringHelper *)index_html);
}
  
void loop() {}

You are right, double quotes have to be escaped.
But don't newlines also terminate strings? How are these handled inside raw strings?

Actually I cannot check your example. It compiles but for some strange reason I cannot change the board type and get an sync error on upload.

They are included in the raw string, just like any other character.

The point of the 'raw' string is that you don't have to escape

You're right.

Using Meld I compared a working version and the non working version of the all program and there it showed that the compiler was right, I didn't remember another change I made some where else in the code.
Still, strangely it was compiling without the //, otherwise I wouldn't have google about this, but after some systems update and a reboot the next day.
Sorry.

@DrDiettrich
Thanks, interesting:

I found that the raw string C++ syntax starts with R"( and ends in )" . Or with a single character delimiter § (almost any char) it starts with R"§( and ends with )§" . There may be a bug in the (undocumented?) rawliteral macro. Try again without rawliteral .

Please see post#2 and provide requested info

I would use the ascii slash character to build up a string with double slash. Something like...

let http = "HTTP:";
let slash = String.fromCharCode(47);
let path = "server.com/dir/file";
let url = http.concat(slash, slash, path);

Just stumbled across this and got a similar issue here so posting an answer as I couldn't find one initially.

If you escape the forwardslashes with a backslash each then it compiles (so https:\/\/ instead of https://

So rendering a web page with an embedded css link looks like this

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https:\/\/cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"

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