Home > OS >  What exact sequence of control characters ends a comment in C ?
What exact sequence of control characters ends a comment in C ?

Time:02-10

The book A Tour of C states that

The double slash, //, begins a comment that extends to the end of the line.

What exact sequence of control characters constitutes the "end of line".

According to this wikipedia article, there are four different ways to represent a new line in ASCII.
These are the following sequences:
LF
CR
LF CR
CR LF

Will all of these work to separate the end of a comment from the beginning of the next line of code?

CodePudding user response:

According to the C 14 Standard (2.2 Phases of translation)

1 The precedence among the syntax rules of translation is specified by the following phases.

  1. Physical source file characters are mapped, in an implementation-defined manner, to the basic source character set (introducing new-line characters for end-of-line indicators) if necessary.

So the end of a line is indicated by the new line character '\n'.

CodePudding user response:

Yes. Any of these should work. CR LF (Windows) and LF (Unix-related) are the most commonly used these days, but the other two have been used historically.

  • Related