I spent several hours this weekend tracking down a bug that highlights something I never knew about GCC (and the Arduino IDE, which uses GCC). At first I was inclined to blame the limited Arduino IDE, but that in itself based on GCC. So I replicated the behavior using command line GCC on a the code below, on both Linux and a Mac.
Compile and run the following code in GCC:
printf(“Hello Line 1\n”) ; // this is a comment
printf(“Hallo Line 2\n”) ; // comment with back \
printf(“Hullo Line 3\n”) ; // This line will not print – try it!
printf(“Hillo Line 4\n”) ; // last line
Line 3 does not print!
As a long time UNIX user, I get what is going on — the backslash forces a line continuation — so line 3 is effectively considered part of the comment on line 2!
But why does GCC parse this way? C/C++ already doesn’t care about line breaks and continuations, since all parsing has well defined delineations. In fact, // is an “exception” that doesn’t require a matching terminating delineation — it is the line feed. But the norm is that it is only used for one-line comments. Except I guess those one-line comments can be continued on the next line …
I came across this issue while editing/debugging a font set and display library for an Arduino display project. I am posting this in case someone else ever tries to google the answer.