Liste des Groupes | Revenir à l c |
On 27/02/2025 12:56, Ar Rakin wrote:This is so weird LMAO, good to know though. But still, I will continue to love C and will still write more C code :-)bart <bc@freeuk.com> writes:It's to do with how C is defined, which requires that its implementation corresponds to series of phases.
>// 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?
Then line-splicing, which combines two lines if the first ends with \, is done before processing // comments.
I am aware that youcan do the same thing with strings like this:It's isn't that useful for strings; the following is simpler and also works:
>
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?
"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.
Les messages affichés proviennent d'usenet.