compile error when //------------\\ is in my code

Hello all,

In my sketch, I wanted to separate sections of code to make it easier to see where individual sections begin. To do this, I commented out a name, such as //NEW SECTION, and then I commented an underline below it, like //-------------\

I got all sorts of compile errors such as "'Serial' was not declared in this scope" and stuff like that.

I got rid of the \ at the end of //-----------------\ and it compiles fine. Any idea what the compiler doesn't like about that?

Just curious. I certainly can avoid doing it. Just thought it looked pretty. :slight_smile:

This is bad:

//NEW SECTION\
//-----------------\

But this is ok:

//NEW SECTION\
//-----------------

Better look up what a backslash does to the compiler.

Thank you for your reply.

I did quite a bit of searching around for why a backslash will cause an error, but all I've seen is it mentioned that backslashes "can sometimes cause errors".

I am assuming that the - followed by the \ is what causes the error, but just wondering why.

I will search more.

The trailing backslash "folds lines". So your line:

//NEW SECTION\\
//-----------------\\
int fubar;

Becomes:

//NEW SECTION\ //-----------------\ int fubar;

So things following the backslash may disappear.

Get rid of "pretty" is my advice. Get rid of backslashes, unless you need them.

You'd be better off using block comments if you want to underline text.

/* NEW SECTION
   ----------- */

If I may suggest, read this "sticky":

Read this before posting a programming question

If you had posted your code, and the error message, rather than excerpting with "all sorts of compile errors" then we might have been able to see the exact problem.

Awesome! Thanks for the info.

And point taken regarding how I posted. I will do better next time. My apologies.

If you had posted your code, and the error message, rather than excerpting with "all sorts of compile errors" then we might have been able to see the exact problem

I disagree - the problem is evident in the thread title!