Compiler seems to remove an array item (SOLVED Continuation Char)

I'm writing a library for everyone (and the internet) to be to easily hook up an LCD/LED controller with a 7 segment display(s).

I'm storing my characters in progmem but for some reason the array item for the backslash character is not present when I have some comments after it. What's going on?

Don't work

PROGMEM const prog_uchar segmentMap[] = {
  B00000000, // 032 SPACE
  :
  B00111001, // 091 [
  B01100100, // 092 \    This line appears to disappear to the compiler/item not in array
  B00001111, // 093 ]
  :
  B00000000  // 127 DEL
};

Works

PROGMEM const prog_uchar segmentMap[] = {
  B00000000, // 032 SPACE
  :
  B00111001, // 091 [
  B01100100,   
  B00001111, // 093 ]
  :
  B00000000  // 127 DEL
};

It's definitely something to do with the characters in my comments, but I just can't work out what. Must be so simple...

The backslash is the escape character. In order to use it in code, you need to escape it. Use 2 backslashes.

Thanks for you reply :slight_smile:

I’m not sure how that would help because I’m not using the backslash in code it’s part of a comment, it follow’s a double forward slash. Shouldn’t that make it part of the comment for that line?

It is a line continuation character, valid even if in a comment

Doesn't seem to matter. I ran into the same problem. Replaced it with the words "back slash". Problem solved.

Thanks to AWOL for pointing this out! :) And also PaulS and Pete C!

I can now continue coding my library feeling like a bit of noob now... :zipper_mouth_face:

Are you sure it was the line with the back slash that was missing from the array, and not the next one?

Yes, you're right, it was the line after that disappeared. It looks like I must have commented out that line by using the continuation character on the previous line!

I can see what I've done though. Here's an example to demonstrate to anyone having/had similar problems:

int a; // declare a \
int b; // b is never declared

compiler sees

int a; // declare a int b; // b is never declared  ** 2nd line part of comment of first

Yup, that's how it works. There was a similar post a few weeks back.

I've just done a quick search on the forums and it looks like it has caught out a few people in the past!

I think it's because other programming languages have continuation characters but they're ignored when in comments. C++ is tricky.