|
|
|
|
|
|
| Author |
Message |
Harald van Dijk *nix forums Guru Wannabe
Joined: 06 Feb 2006
Posts: 123
|
Posted: Wed Jun 21, 2006 9:18 pm Post subject:
Re: // vs /*
|
|
|
Ben Pfaff wrote:
| Quote: | Richard Heathfield <invalid@invalid.invalid> writes:
Since a strictly conforming program won't have any nested
comments in it, it won't notice that they're allowed, so
there's no conformance issue.
Strictly conforming programs can be broken by a nested comment
extension, e.g.
/*#include <stdio.h> /* Not needed, why was this here? */
|
I think the logic was that */ can't occur outside of a comment in a
s.c. program, so if the compiler encountered */ outside of a comment,
it could re-preprocess the file, this time while supporting nested
comments, so I think an example like this would explain it better:
int main(void) {
return 0 /* /* */ *// 0;
0;
} |
|
| Back to top |
|
 |
neutron*star *nix forums Guru
Joined: 21 Feb 2005
Posts: 2039
|
Posted: Wed Jun 21, 2006 9:24 pm Post subject:
Re: // vs /*
|
|
|
Ben Pfaff said:
| Quote: | Richard Heathfield <invalid@invalid.invalid> writes:
Since a strictly conforming program won't have any nested
comments in it, it won't notice that they're allowed, so
there's no conformance issue.
Strictly conforming programs can be broken by a nested comment
extension, e.g.
/*#include <stdio.h> /* Not needed, why was this here? */
|
Fair comment... er, I mean, fair point. But if I can just clutch at a straw
as I go hurtling over the cliff, I'd like to point out that your example's
comment isn't actually a nested comment, since it has insufficiently many
closing */s.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously) |
|
| Back to top |
|
 |
Andrew Poelstra *nix forums Guru
Joined: 05 Nov 2005
Posts: 345
|
Posted: Wed Jun 21, 2006 10:06 pm Post subject:
Re: // vs /*
|
|
|
On 2006-06-21, Harald van Dijk <truedfx@gmail.com> wrote:
| Quote: | Ben Pfaff wrote:
Richard Heathfield <invalid@invalid.invalid> writes:
Since a strictly conforming program won't have any nested
comments in it, it won't notice that they're allowed, so
there's no conformance issue.
Strictly conforming programs can be broken by a nested comment
extension, e.g.
/*#include <stdio.h> /* Not needed, why was this here? */
I think the logic was that */ can't occur outside of a comment in a
s.c. program, so if the compiler encountered */ outside of a comment,
it could re-preprocess the file, this time while supporting nested
comments, so I think an example like this would explain it better:
int main(void) {
return 0 /* /* */ *// 0;
0;
}
|
Wow, that made my head hurt. I couldn't figure out what *// could
mean. Is it closing or opening a comment?
Compiler supports nesting:
Compiler supports //:
return 0 / 0; /* Dividing by 0 is undefined. */
return 0 0; /* This might also be possible. */
Compiler doesn't support //:
return 0 / 0; /* Dividing by 0 is undefined. */
Compiler doesn't support nesting:
Compiler supports //:
return 0 * 0;
Compiler doesn't support //:
return 0 *// 0; /* Syntax error */
--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
I know that area of town like the back of my head. |
|
| Back to top |
|
 |
Keith Thompson *nix forums Guru
Joined: 28 Feb 2005
Posts: 5173
|
Posted: Wed Jun 21, 2006 10:06 pm Post subject:
Re: // vs /*
|
|
|
Richard Heathfield <invalid@invalid.invalid> writes:
[...]
| Quote: | Comments should be used to comment code, not to disable it.
If you want temporarily to disable a bunch of code, this is very easy to do
without comments:
#if 0
foo(); /* widgetify the grommets */
bar(); /* fudge the custard grinder */
#endif
And you can trivially re-enable the code by changing a single character.
|
I agree completely in the context of C as it's currently defined
(which is, of course, the topic of this newsgroup).
But if you look at programming languages in general, most of them
don't have C's "#if ... "#endif" construct. In such languages, if
they have end-of-line comments (delimited by, say, "//", or "#", or
"--"), then commenting out blocks of code is perfectly reasonable.
And if C had retained BCPL's "//" end-of-line comments, rather than
replacing them with "/* ... */" (and re-adding "//" many years later),
then I would argue that commenting out blocks of C code would be
equally reasonable.
The trailing '\' problem is significant, of course, but as long as I'm
changing history I'll get rid of that problem as well ... somehow.
[...]
| Quote: | I have three principal objections to them. Firstly, it is all too easy, on
Win32 platforms, to do this:
foo(); // widgetify the grommets, default directory is c:\temp\
bar(); // why oh WHY isn't this being called?
|
That's something I hadn't thought of before this thread. I would
*hope* that a compiler would issue a warning for this kind of thing --
and for a '\' followed by whitespace, which *doens't* cause line
splicing.
| Quote: | Secondly, I've already mentioned elsethread that switching them on also
switches off ANSI conformance in my implementation.
|
Good point.
| Quote: | Thirdly, they encourage the appalling practice of "commenting out" code
instead of disabling it properly.
|
I disagree on this point, but of course it's a matter of taste.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. |
|
| Back to top |
|
 |
Mark McIntyre *nix forums Guru
Joined: 16 Feb 2005
Posts: 1564
|
Posted: Wed Jun 21, 2006 10:50 pm Post subject:
Re: // vs /*
|
|
|
On Wed, 21 Jun 2006 20:57:18 +0000, in comp.lang.c , Richard
Heathfield <invalid@invalid.invalid> wrote:
| Quote: | Conforming compilers are allowed to provide extensions, provided
a strictly conforming program doesn't notice those extensions.
|
Hmm. This argument can be applied to void main() and treating pointers
as ints. Are you sure you want to use it?
--
Mark McIntyre
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan |
|
| Back to top |
|
 |
Andrew Poelstra *nix forums Guru
Joined: 05 Nov 2005
Posts: 345
|
Posted: Wed Jun 21, 2006 11:16 pm Post subject:
Re: // vs /*
|
|
|
On 2006-06-21, Mark McIntyre <markmcintyre@spamcop.net> wrote:
| Quote: | On Wed, 21 Jun 2006 20:57:18 +0000, in comp.lang.c , Richard
Heathfield <invalid@invalid.invalid> wrote:
Conforming compilers are allowed to provide extensions, provided
a strictly conforming program doesn't notice those extensions.
Hmm. This argument can be applied to void main() and treating pointers
as ints. Are you sure you want to use it?
|
Why not? Both of those may be allowed, but they're no more topical
to clc than nested comments are. Nor is it guaranteed that they are
any more or less portable.
--
Andrew Poelstra < http://www.wpsoftware.net/blog >
To email me, use "apoelstra" at the above address.
I know that area of town like the back of my head. |
|
| Back to top |
|
 |
neutron*star *nix forums Guru
Joined: 21 Feb 2005
Posts: 2039
|
Posted: Wed Jun 21, 2006 11:27 pm Post subject:
Re: // vs /*
|
|
|
Keith Thompson said:
| Quote: | Richard Heathfield <invalid@invalid.invalid> writes:
[...]
snip
#endif
And you can trivially re-enable the code by changing a single character.
I agree completely in the context of C as it's currently defined
|
Fabulous.
| Quote: | (which is, of course, the topic of this newsgroup).
|
Right.
| Quote: | But if you look at programming languages in general,
|
....then you stray from the topic! :-)
Seriously, my comments(!) are relevant only to C and its close relatives.
Whether they apply to programming languages in general is impossible to
answer. Such matters of style are heavily syntax-dependent. For example, if
C didn't have line-splicing, a third of my objection would fall away. If C
didn't have a preprocessor, bang would go another third. And if C had
supported // comments in C89, the remainder of my case would collapse in a
sad little heap on the floor.
But it does, and it does, and it didn't, so it doesn't, and it doesn't, and
it doesn't. In that order.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously) |
|
| Back to top |
|
 |
neutron*star *nix forums Guru
Joined: 21 Feb 2005
Posts: 2039
|
Posted: Wed Jun 21, 2006 11:29 pm Post subject:
Re: // vs /*
|
|
|
Mark McIntyre said:
| Quote: | On Wed, 21 Jun 2006 20:57:18 +0000, in comp.lang.c , Richard
Heathfield <invalid@invalid.invalid> wrote:
Conforming compilers are allowed to provide extensions, provided
a strictly conforming program doesn't notice those extensions.
Hmm. This argument can be applied to void main() and treating pointers
as ints. Are you sure you want to use it?
|
Sure. Any compiler is allowed to accept void main as an extension. We always
knew that. That doesn't mean that void main programs are correct in the
comp.lang.c sense (because no compiler is /required/ to accept void main,
and some implementations do indeed reject it).
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously) |
|
| Back to top |
|
 |
Kenneth Brody *nix forums Guru
Joined: 20 Apr 2005
Posts: 401
|
Posted: Thu Jun 22, 2006 3:41 pm Post subject:
Re: // vs /*
|
|
|
Bill Pursell wrote:
| Quote: |
Kenneth Brody wrote:
/* This is a comment /* with a nested comment */ inside of it. */
// And just for completeness // this is nested
while this line is part of the outer comment!!
|
It depends. With "/*...*/" comments, the closing "*/" is consumed
as part of the comment, whereas with "//" comments the closing
newline is not part of the comment, and remains. One could argue
that the newline closes both "//" comments.
And, just to make things "interesting", what about nesting mixed
comment styles?
Like this:
i++; // this is a comment /* what about this?
"is this a comment, or real code?"
is this a symtax error? */
Or:
i++; /* This is a comment // some more */
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@gmail.com> |
|
| Back to top |
|
 |
Kenneth Brody *nix forums Guru
Joined: 20 Apr 2005
Posts: 401
|
Posted: Thu Jun 22, 2006 3:54 pm Post subject:
Re: // vs /*
|
|
|
Richard Heathfield wrote:
[...]
| Quote: | I have three principal objections to them. Firstly, it is all too easy, on
Win32 platforms, to do this:
foo(); // widgetify the grommets, default directory is c:\temp\
bar(); // why oh WHY isn't this being called?
[...] |
Eww... I hadn't realized that would continue the comment onto the
second line. (Not that I'd ever use such a construct, mind you.)
But, you are correct, and the call to bar() disappears inside the
comment. (At least with MSVC6. Is this guaranteed by the Standard?)
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@gmail.com> |
|
| Back to top |
|
 |
neutron*star *nix forums Guru
Joined: 21 Feb 2005
Posts: 2039
|
Posted: Thu Jun 22, 2006 4:03 pm Post subject:
Re: // vs /*
|
|
|
Kenneth Brody said:
| Quote: | Richard Heathfield wrote:
[...]
I have three principal objections to them. Firstly, it is all too easy,
on Win32 platforms, to do this:
foo(); // widgetify the grommets, default directory is c:\temp\
bar(); // why oh WHY isn't this being called?
[...]
Eww... I hadn't realized that would continue the comment onto the
second line. (Not that I'd ever use such a construct, mind you.)
But, you are correct, and the call to bar() disappears inside the
comment. (At least with MSVC6. Is this guaranteed by the Standard?)
|
Yes. Line-splicing happens in Translation Phase 2, whereas comment removal
doesn't happen until Translation Phase 3.
The reason I mentioned Win32 is only that its gerharsterly habit of using
the \ character as a path separator makes it more likely for such comments
to appear in Win32 programs. Other platforms are not immune by any means.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously) |
|
| Back to top |
|
 |
Rob Thorpe *nix forums addict
Joined: 27 Jun 2005
Posts: 50
|
Posted: Thu Jun 22, 2006 4:45 pm Post subject:
Re: // vs /*
|
|
|
Richard Heathfield wrote:
| Quote: | Bill Pursell said:
Keith Thompson wrote:
Ryan Reich <ryan.reich@gmail.com> writes:
To uncomment is another story, since text is line-based but /* */ is
non-local, but in practice you have either syntax highlighting, so
the editor knows this non-local information, or you follow a common
style and put a * at the beginning of each commented line, in which
case for the purposes of automation there is no difference between
/* */ and //.
Actually, there is. Adding either "// " or "* " to the beginning of
each of a range of lines is typically a single operation. In the
latter case, adding the "/*" at the top and the "*/" at the bottom is
another separate operation (unless you define a macro to do the whole
thing, which is admittedly a reasonable approach). But again, you'll
run into problems with nested comments.
One of the major reasons I like end-of-line comments is that they're
localized. It's obvious what is and is not commented out on a given
line without having to look up or down the file for a comment
delimiter.
snip
Removing one layer of the comment symbol exposes
the 3 lines of code and leaves the original comment
as a comment.
Comments should be used to comment code, not to disable it.
If you want temporarily to disable a bunch of code, this is very easy to do
without comments:
#if 0
foo(); /* widgetify the grommets */
bar(); /* fudge the custard grinder */
#endif
And you can trivially re-enable the code by changing a single character.
But for some reason I have a visceral reaction to // in
C code. I suppose I'm being completely irrational, but
it just really irks me.
I have three principal objections to them. Firstly, it is all too easy, on
Win32 platforms, to do this:
foo(); // widgetify the grommets, default directory is c:\temp\
bar(); // why oh WHY isn't this being called?
Secondly, I've already mentioned elsethread that switching them on also
switches off ANSI conformance in my implementation.
|
That's a beautiful little code snippet.
I think that some of the nested comment code is also fit for use in the
IOCCC.
Regarding #if and it's disadvantages, I would point out that you can do
both.
That is if you do:-
#if 0
/*
.... code ...
/*
#endif
Then the problem with nested parens AFAIK does not occur. An if you
have a colouring editor it will recognise the comment.
I don't do this though, I use an editor that recognises #ifs. |
|
| Back to top |
|
 |
CBFalconer *nix forums Guru
Joined: 09 Mar 2005
Posts: 2502
|
Posted: Thu Jun 22, 2006 10:08 pm Post subject:
Re: // vs /*
|
|
|
Kenneth Brody wrote:
| Quote: |
.... snip ...
And, just to make things "interesting", what about nesting mixed
comment styles?
Like this:
i++; // this is a comment /* what about this?
"is this a comment, or real code?"
is this a symtax error? */
Or:
i++; /* This is a comment // some more */
|
All adequately handled by the simple rule "after /* everything up
to and including a */ is comment". Similarly, "after // everything
up to end-of-line is comment".
--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@maineline.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE maineline address! |
|
| Back to top |
|
 |
Mark McIntyre *nix forums Guru
Joined: 16 Feb 2005
Posts: 1564
|
Posted: Thu Jun 22, 2006 10:27 pm Post subject:
Re: // vs /*
|
|
|
On Wed, 21 Jun 2006 23:29:28 +0000, in comp.lang.c , Richard
Heathfield <invalid@invalid.invalid> wrote:
| Quote: | Mark McIntyre said:
On Wed, 21 Jun 2006 20:57:18 +0000, in comp.lang.c , Richard
Heathfield <invalid@invalid.invalid> wrote:
Conforming compilers are allowed to provide extensions, provided
a strictly conforming program doesn't notice those extensions.
Hmm. This argument can be applied to void main() and treating pointers
as ints. Are you sure you want to use it?
Any compiler is allowed to accept void main as an extension.
|
Sure, but thats not the point, is it?
Anyway, I'll remember you said this, sometime.... :-)
--
Mark McIntyre
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan |
|
| Back to top |
|
 |
neutron*star *nix forums Guru
Joined: 21 Feb 2005
Posts: 2039
|
Posted: Thu Jun 22, 2006 11:14 pm Post subject:
Re: // vs /*
|
|
|
Mark McIntyre said:
| Quote: | On Wed, 21 Jun 2006 23:29:28 +0000, in comp.lang.c , Richard
Heathfield <invalid@invalid.invalid> wrote:
Mark McIntyre said:
On Wed, 21 Jun 2006 20:57:18 +0000, in comp.lang.c , Richard
Heathfield <invalid@invalid.invalid> wrote:
Conforming compilers are allowed to provide extensions, provided
a strictly conforming program doesn't notice those extensions.
Hmm. This argument can be applied to void main() and treating pointers
as ints. Are you sure you want to use it?
Any compiler is allowed to accept void main as an extension.
Sure, but thats not the point, is it?
|
Um, yes it is, actually.
| Quote: | Anyway, I'll remember you said this, sometime....
|
To save you the trouble, just remember 1.7 COMPLIANCE instead:
"A conforming implementation may have extensions (including additional
library functions), provided they do not alter the behavior of any strictly
conforming program."
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously) |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Sat Jan 10, 2009 12:52 am | All times are GMT
|
|
Remortgages | Internet Advertising | Bankruptcy | Web Advertising | Debt Consolidation
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|