[comp.lang.c] Lisp-style comments

julian@uhccux.uhcc.hawaii.edu (Julian Cowley) (04/27/89)

Someone told me recently that the latest ANSI draft has
Lisp-style comments, where two slashes at the beginning of a line
mean that the rest of the line is to be treated as a comment.  Is
this true, or is it just wishful thinking?

julian@uhccux.uhcc.hawaii.edu
uunet!ucsd!nosc!uhccux!julian
julian@uhccux.bitnet

gwyn@smoke.BRL.MIL (Doug Gwyn) (04/27/89)

In article <3851@uhccux.uhcc.hawaii.edu> julian@uhccux.uhcc.hawaii.edu (Julian Cowley) writes:
>Someone told me recently that the latest ANSI draft has
>Lisp-style comments, where two slashes at the beginning of a line
>mean that the rest of the line is to be treated as a comment.  Is
>this true, or is it just wishful thinking?

I suggest you find a more reliable source of information.

C++ supports //-comment-to-end-of-line as well as C's /*comment*/.
But C++ is not ANSI C.

henry@utzoo.uucp (Henry Spencer) (04/27/89)

In article <3851@uhccux.uhcc.hawaii.edu> julian@uhccux.uhcc.hawaii.edu (Julian Cowley) writes:
>Someone told me recently that the latest ANSI draft has
>Lisp-style comments, where two slashes at the beginning of a line
>mean that the rest of the line is to be treated as a comment.  Is
>this true, or is it just wishful thinking?

Wishful thinking.  He's probably confusing ANSI C with C++.  C++ does
have an alternate comment style in which // anywhere (not just at the
beginning of a line) starts a comment which runs to the end of the line.
This has also been a popular extension to C compilers, which may have
added to the confusion.  As of the Oct draft, it definitely is not part
of ANSI C, and I think I'd have heard about it if X3J11 was crazy enough
to make such a significant change at this late date.
-- 
Mars in 1980s:  USSR, 2 tries, |     Henry Spencer at U of Toronto Zoology
2 failures; USA, 0 tries.      | uunet!attcan!utzoo!henry henry@zoo.toronto.edu

desnoyer@Apple.COM (Peter Desnoyers) (04/27/89)

In article <10150@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes:
>In article <3851@uhccux.uhcc.hawaii.edu> julian@uhccux.uhcc.hawaii.edu (Julian Cowley) writes:
>> [//-style comments]
>
>C++ supports //-comment-to-end-of-line as well as C's /*comment*/.
>But C++ is not ANSI C.

Not to be confused with the fact that at least one
draft-ANSI-compliant compiler (MPW C) has an option to take such
comments. 

				Peter Desnoyers

ddb@ns.network.com (David Dyer-Bennet) (04/29/89)

In article <10150@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes:
:In article <3851@uhccux.uhcc.hawaii.edu> julian@uhccux.uhcc.hawaii.edu (Julian Cowley) writes:
:>Someone told me recently that the latest ANSI draft has
:>Lisp-style comments, 
:I suggest you find a more reliable source of information.

Microsoft C 5.1 has added some sort of comment-to-end-of-line syntax,
I believe.  I think it's also a double slash; I don't use it (at least
yet).  With both them and (according to another followup) some Mac C
adding it, anybody got any idea where the idea came from (since I take it
as given that Doug Gwyn is right about its not being in the ANSI draft)?
Was it perhaps discussed or proposed, and finally turned down after feature
freeze on those particular compilers?

-- 
David Dyer-Bennet, ddb@terrabit.fidonet.org, or ddb@ns.network.com
or ddb@Lynx.MN.Org, ...{amdahl,hpda}!bungia!viper!ddb
or ...!{rutgers!dayton | amdahl!ems | uunet!rosevax}!umn-cs!ns!ddb
or Fidonet 1:282/341.0, (612) 721-8967 9600hst/2400/1200/300

gwyn@smoke.BRL.MIL (Doug Gwyn) (04/29/89)

In article <29650@apple.Apple.COM> desnoyer@Apple.COM (Peter Desnoyers) writes:
>>> [//-style comments]
>... at least one draft-ANSI-compliant compiler (MPW C) has an option
>to take such comments. 

I don't think it is standard conformant when it is in such a mode.
(Consider stringizing to see how the bahavior could depend on this.)

gwyn@smoke.BRL.MIL (Doug Gwyn) (04/29/89)

In article <1338@ns.network.com> ddb@ns.UUCP (David Dyer-Bennet) writes:
>Was it perhaps discussed or proposed, and finally turned down after feature
>freeze on those particular compilers?

Certainly //comment-to-end-of-line was proposed and discussed, but it
was never accepted for inclusion in the C standard because it never
was considered part of the official C language by anybody we know of.
One comment style is sufficient.

I first saw //comments supported by a C compiler in use at the Naval
Postgraduate School, and I thought it was sufficiently useful that
I added it to Geotronics Corp's PDP-11 C compiler and preprocessor.
It was useful all right, but when we had to upgrade to a VAX its C
compiler and preprocessor did not like our //comments.  Therefore I
was faced with the choice of insisting that every C compiler we ever
wanted to use be modified to support //comments, or else convert all
our source code into genuine //-free C.  I did the latter and
considered that I had learned a lesson.

//comments have since been seen in "C with classes" and its current
descendant C++.  It's convenient if you have it but if you're writing
C code that needs to be widely portable you dare not use this feature.

tneff@bfmny0.UUCP (Tom Neff) (04/30/89)

In article <10173@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes:
>...//comments have since been seen in "C with classes" and its current
>descendant C++.  It's convenient if you have it but if you're writing
>C code that needs to be widely portable you dare not use this feature.

If there were a portable public-domain convert program that could
transform //commented C into /* commented */ C, you could hand that out
along with any //code you distributed, and so be sure that everyone
could build your product.  You could even add a 'comment:' entry to
your Makefile to fix everything in place.  Just a thought...
-- 
Tom Neff				UUCP:     ...!uunet!bfmny0!tneff
    "Truisms aren't everything."	Internet: tneff@bfmny0.UU.NET

jeremyr@cs.qmc.ac.uk (Jeremy Roussak) (05/01/89)

> [much talk of // comments]

Comments beginning // are the standard in BCPL, the language from which C
is supposedly derived.  I think they're rather better (you can't get funny
messages from the compiler by forgetting the closing */, for example).
Does anyone know why those responsible for BCPL's metamorphosis into C
chose to alter this?

On a slightly different note, why did the same people choose to make
BCPL's break and endcase both be called break in C, losing the ability
to break out of loops while inside a case clause?

Jeremy Roussak

cs132046@brunix (Garrett Fitzgerald) (05/01/89)

There is one problem with using //. If you have multi-line comments, and you
need to do a big addition in the middle, you have to do a lot of reformatting.
With /*...*/, there is no problem with this.
--------------------------------
"Take my Worf--please!" -- Data
Sarek of Vulcan, a.k.a. Garrett Fitzgerald
cs132046@brunix or st902620@brownvm.bitnet

bright@Data-IO.COM (Walter Bright) (05/02/89)

In article <1338@ns.network.com> ddb@ns.UUCP (David Dyer-Bennet) writes:
>Microsoft C 5.1 has added some sort of comment-to-end-of-line syntax,
>I believe.

It's the // to end of line. It's borrowed from C++. Do not use this feature
if you want your C code to be portable. It's not K&R C or ANSI C.

If you want these features, why not go all the way and get C++?

henry@utzoo.uucp (Henry Spencer) (05/02/89)

In article <14292@bfmny0.UUCP> tneff@bfmny0.UUCP (Tom Neff) writes:
>>... It's convenient if you have it but if you're writing
>>C code that needs to be widely portable you dare not use this feature.
>
>If there were a portable public-domain convert program that could
>transform //commented C into /* commented */ C, you could hand that out
>along with any //code you distributed, and so be sure that everyone
>could build your product...

This sort of solution often gets advocated in such cases.  It doesn't
work too well in practice, unfortunately.  What happens when you get an
update in the form of a diff script?  What happens if the user doesn't
have the disk space to hold both original and commentized versions?
Which version do you make changes to (hint:  there is no one right answer)?
It's not worth the trouble for such a minor notational point.
-- 
Mars in 1980s:  USSR, 2 tries, |     Henry Spencer at U of Toronto Zoology
2 failures; USA, 0 tries.      | uunet!attcan!utzoo!henry henry@zoo.toronto.edu

raymond@ptolemy.arc.nasa.gov (Eric A. Raymond) (05/02/89)

In article <5330@brunix.UUCP> cs132046@cslab0a.UUCP (Garrett Fitzgerald) writes:
>There is one problem with using //. If you have multi-line comments, and you
>need to do a big addition in the middle, you have to do a lot of reformatting.

[I should probably know better, but ...]

That they are useful in one context, isn't diminished by the fact that
they aren't useful in all contexts.



-- 
Eric A. Raymond  (raymond@ptolemy.arc.nasa.gov)
G7 C7 G7 G#7 G7 G+13 C7 GM7 Am7 Bm7 Bd7 Am7 C7 Do13 G7 C7 G7 D+13: Elmore James

gorpong@telxon.UUCP (Gordon C. Galligher) (05/10/89)

In article <964@sequent.cs.qmc.ac.uk>, jeremyr@cs.qmc.ac.uk (Jeremy Roussak) writes:
> 
> > [much talk of // comments]
> 
> [BCPL stuff on // comments]
> 
> On a slightly different note, why did the same people choose to make
> BCPL's break and endcase both be called break in C, losing the ability
> to break out of loops while inside a case clause?
> 
> Jeremy Roussak

Jeremy, you can always break out of a loop from within a case.  C does allow
the (-: goto :-).

		-- Gordon.
-- 
Gordon C. Galligher  <|> ...!uunet!telxon!gorpong <|> gorpong@teleng.uucp.uu.net
Telxon Corporation   <|> "Captain, I hardly believe that insults are within your
Akron, Ohio, 44313   <|> prerogative as my commanding officer" - Spock
(216) 867-3700 (3512)<|>   (City on the Edge of Forever (Starring Joan Collins))