Rectangle 27 0

gcc What is the meaning of multi line comment warnings in C?


//**********|ANSWER|************\//blah blah blah, answering the
//questions, etc etc
int i = 42;

// backslash+space: \ 
i++
// backslash and no space: \
i--
printf("%d\n", i);

A backslash as the last character on a line means that the compiler should disregard the backslash and the newline character - it tells the compiler to do this before it should check for comments. So it says that before removing comments it should effectively look at

Another reason is that even if had known this is that normally an editor will not visibly show whitespace and it's therefore easy to miss that the backslash may or may not be the last character on the line. For example:

In your example it isn't since the second line is a comment anyway, but what if you had written something useful on the second line?

Well since you asked question "a" it's likely that you didn't realize that the compiler behaved this way, and if you don't realize that you've commented out a line of code, then it's quite nice of the compiler to warn you.

Would result in 43 since the i-- is commented out, but i++ isn't (because the backslash is not the last character on the line, but a space is).

a) how exactly does the presence of the backslash characters make it a "multi-line comment", and

b) why would a multi-line comment be a problem anyway?

it now sees the // at the start and ignores the rest of the line

Note
Rectangle 27 0

gcc What is the meaning of multi line comment warnings in C?


//**********|ANSWER|************\//blah blah blah, answering the
//questions, etc etc
int i = 42;

// backslash+space: \ 
i++
// backslash and no space: \
i--
printf("%d\n", i);

A backslash as the last character on a line means that the compiler should disregard the backslash and the newline character - it tells the compiler to do this before it should check for comments. So it says that before removing comments it should effectively look at

Another reason is that even if had known this is that normally an editor will not visibly show whitespace and it's therefore easy to miss that the backslash may or may not be the last character on the line. For example:

In your example it isn't since the second line is a comment anyway, but what if you had written something useful on the second line?

Well since you asked question "a" it's likely that you didn't realize that the compiler behaved this way, and if you don't realize that you've commented out a line of code, then it's quite nice of the compiler to warn you.

Would result in 43 since the i-- is commented out, but i++ isn't (because the backslash is not the last character on the line, but a space is).

a) how exactly does the presence of the backslash characters make it a "multi-line comment", and

b) why would a multi-line comment be a problem anyway?

it now sees the // at the start and ignores the rest of the line

Note
Rectangle 27 0

gcc What is the meaning of multi line comment warnings in C?


But if the next line was not intended to be a comment, then you might have ended up with "weird behavior": compiler ignoring the second line for no apparent reason. The situation is often complicated by the fact that some syntax-highlighting code editors do not detect this situation and fail to highlight the next line as a comment.

Generally, for this specific reason, it is not a good idea to abuse the \ character as code level. Use it only if you really have to, i.e. only if you really want to stitch several lines into one.

The compiler simply tells you that you might have inadvertently commented-out the next line of code by ending the previous comment line with \, which is a line continuation character in C. This causes the second line to get concatenated with the first. This in turn makes the // comment to actually comment-out both original lines. In your case it is not a problem, since the next line is a comment as well.

Note
Rectangle 27 0

gcc What is the meaning of multi line comment warnings in C?


But if the next line was not intended to be a comment, then you might have ended up with "weird behavior": compiler ignoring the second line for no apparent reason. The situation is often complicated by the fact that some syntax-highlighting code editors do not detect this situation and fail to highlight the next line as a comment.

Generally, for this specific reason, it is not a good idea to abuse the \ character as code level. Use it only if you really have to, i.e. only if you really want to stitch several lines into one.

The compiler simply tells you that you might have inadvertently commented-out the next line of code by ending the previous comment line with \, which is a line continuation character in C. This causes the second line to get concatenated with the first. This in turn makes the // comment to actually comment-out both original lines. In your case it is not a problem, since the next line is a comment as well.

Note
Rectangle 27 0

gcc What is the meaning of multi line comment warnings in C?


/**********|ANSWER|************/
//**********|ANSWER|************\\
//**********|ANSWER|************//
/////////// |ANSWER| ////////////

But a backslash at the end of a line causes that line to be spliced to the next line. So you can legally introduce a comment with //, put a backslash at the end of the line, and cause the comment to span multiple physical lines (but only one logical line).

C (since the 1999 standard) has two forms of comments.

C++-style comments are introduced by // and terminated by the end of the line.

Just use something other than backslash at the end of the line, for example:

Old-style comments are introduced by /* and terminated by */, and can span a portion of a line, a complete line, or multiple lines.

That's what you're doing on your first line:

Though even that is potentially misleading, since it almost looks like an old-style /* .. */ comment. You might consider something a little simpler:

Note
Rectangle 27 0

gcc What is the meaning of multi line comment warnings in C?


/**********|ANSWER|************/
//**********|ANSWER|************\\
//**********|ANSWER|************//
/////////// |ANSWER| ////////////

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

But a backslash at the end of a line causes that line to be spliced to the next line. So you can legally introduce a comment with //, put a backslash at the end of the line, and cause the comment to span multiple physical lines (but only one logical line).

C (since the 1999 standard) has two forms of comments.

C++-style comments are introduced by // and terminated by the end of the line.

Just use something other than backslash at the end of the line, for example:

Old-style comments are introduced by /* and terminated by */, and can span a portion of a line, a complete line, or multiple lines.

That's what you're doing on your first line:

Though even that is potentially misleading, since it almost looks like an old-style /* .. */ comment. You might consider something a little simpler:

Note