Sujet : Re: Which code style do you prefer the most?
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 27. Feb 2025, 15:18:40
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vpps7v$34tq7$1@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla Thunderbird
On 27/02/2025 12:56, Ar Rakin wrote:
bart <bc@freeuk.com> writes:
// isn't devoid of quirks (this is still C after all), for example:
>
fopen(file,"rb"); // open file in \windows\system32\
fread(...);
>
Here, the // line continues onto the next, so that the fread is
commented out. But they are fewer.
Interesting. Isn't this considered a compiler bug?
It's to do with how C is defined, which requires that its implementation corresponds to series of phases.
Then line-splicing, which combines two lines if the first ends with \, is done before processing // comments.
I am aware that you
can do the same thing with strings like this:
fprintf(stderr, "multi\
line\
strings\
are fun.");
I can understand how this might be useful; but with *comments*?? Was
that actually a thing in the official C standards?
It's isn't that useful for strings; the following is simpler and also works:
"multi"
"line"
"string"
But it is needed for multi-line macros, as C's proprocessor is strictly line-oriented and a macro definition must fit onto one line.
So lines spliced with \ can be used to combine multiple lines into one. A side-effect is that you can't use // comments for individual lines of a multi-line macro, it would screw things up.
To me it just feels like a compiler bug that was never fixed.
To me the whole of C feels like one huge language bug!
The way line splicing works has even weirder repercussions; any token can be split across lines:
i\
n\
t abc; // split 'int' across 3 lines
/\
/ This is a '//' comment with // split across two lines
/\
* This is a /* ... comment */
"ABC\
nDEF" // A split string escape code
if (a =\
= b) ...
In fact, any C source file can be written with one character per line, plus the \ line continuation.