Malcolm McLean said:
Keith Thompson said:
Malcolm McLean said:
news:
[email protected]... [...]
Congratulations. Was there some reason you snipped my sample code and
added your own? Or did you just stop reading at that point?
Stopped reading.
Ok. In the future, please do me (and the rest of your readers) the
courtesy of reading the whole article before you post a followup.
You'll look less foolish.
I tend to assume that code will reflect the English. In your case you
said that a double slash was a legal C construct if the second slash
was part of a comment.
Not quite. What I said was that *in C90* a double slash could be a
division operator immediately followed by the first character of a /*
.... */ comment. In C99 (which is also C), a double slash can
introduce a comment.
So I assumed that the code was designed to
illustrate that.
It was, after allowing for the C99 correction above.
That was my mistake, but the general rule is that
people read code if they intend to run it or alter it, comments if
they intend to understand what it does.
Here's what I wrote upthread, excluding quoted text. I encourage you
to read it all this time.
| // introduces a comment in C99.
|
| In C90, // could be a division operator immediately followed by the
| first character of a /* ... */ comment.
|
| For example:
|
| #include <stdio.h>
| int main(void)
| {
| char *messages[] = {
| "// comments are not accepted",
| "// comments are accepted"
| };
| int i = 2 //**/ 2
| - 1;
| puts(messages
);
| return 0;
| }
In your followup, you snipped everything starting with "For example:",
and wrote this:
| Aha, we can do it
|
| x = 2 //* C comment */ 2;
| ;
|
| Now we've got x = 2 in C++ and x = 1 in C.
So you wrote a code snippet that illustrates exactly the same point
that mine did (except that you incorrectly ignored the fact that C99
supports // comments). You also gave the false impression that I had
merely made a general comment and that you had jumped in to provide
the specific example that I had failed to provide.