Sujet : Re: Which code style do you prefer the most?
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 27. Feb 2025, 00:17:33
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vpo7ec$2ovro$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla Thunderbird
On 26/02/2025 21:44, Lawrence D'Oliveiro wrote:
On Wed, 26 Feb 2025 14:26:41 +0100, Janis Papanagnou wrote:
Personally (in "C") I prefer '//' though.
I don’t know why, really. C started with the “/* ... */”, and that remains
more versatile with its ability to be inserted in more places.
It's also more error prone: leave out a */ or have a typo in it, and the comment is extended to the closing */ of the next comment.
They can't be nested: if a block of code contains /*...*/ comments, you can't use an outer /*...*/ to comment out that block, as the comment will end at the closing */ of the first nested comment.
There are various other problems: if you want to divide A by *P and write it like this, it gets confusing:
a/*p /* real comment */
The divide op is silently commented out, and you have to rely on other context to cause a detectable error.
// 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.
(Most here will argue that syntax highlighting will help here, but the capabilities vary greatly. It's dangerous to rely on that.)