Issue with ":\" at the end of comments

23 Jun 2018

I'm not sure if this is a bug or something that shouldn't be done in comments. Using the online compiler I'm finding that if I add ":\" to the end of my comment it fails to recognise the line directly below it. I imagine it's because of the "\". Here's an example modified HelloWorld to show the issue.

#include "mbed.h"

// problem comment :\
DigitalOut LED(p30);

int wait_time = 100;

int main() {
    
    while(1) {
        LED = 1;
    }
}

The error I get:

Error: Identifier "LED" is undefined in "main.cpp", Line: 11, Col: 10

23 Jun 2018

The ''\'' at the end of the comment line tells the compiler that this is a multi-line comment. This means the next line is also interpreted as a comment. The declaration of LED is seen as a comment by the compiler and so you get the 'Error: Identifier "LED" is undefined in "main.cpp", Line: 11, Col: 10'

The handling of '\' by the online compiler is expected behaviour. The problem is that some editors don't get it and colour coding doesn't work reliably: 'DigitalOut LED(p30);' should also have been shown in green font to indicate that it is still part of a comment.