From: Keith Thompson on
BruceS <bruces42(a)hotmail.com> writes:
[...]
> <OT> AIUI, C++ accepts /* */ multiline comments without artificially
> terminating said comments at the end of line. I don't have a C++
> Standard in front of me, so I can't confirm that it isn't simply an
> artifact of environments in which I've written C++, but I'm relatively
> confident that these work the same as in C. </OT>

In both C and C++, a comment that begins with /* is not
"artificially" terminated at the end of the line. Instead, it's
"artificially" terminated by the next */. (In other words, I'm
not sure what's so artificial about it.)

> According to The C Standard, 6.4.9p2, C allows comments that *do*
> automatically terminate at the end of the line, just as this style of
> comment works in C++.
[...]

Yes, both C and C++ now permit comments introduced by // and
terminated by the end of the line. These were introduced in BCPL,
one of C's distant ancestors from the 1960s. But they were dropped
from C, and only reintroduced by the 1999 ISO C standard (which
superseded the 1990 ISO C standard, which itself superseded the
de facto standard of Kernighan & Ritchie's book). C++ has always
supported // comments.

Today, most C compilers fully support at least the C90 standard,
but only a subset of the C99 standard. // comments are very widely
supported. On the other hand, they can be rejected if you choose
to invoke your C compiler in a strict C90-conforming mode, or if
you're using a sufficiently old compiler, so /*...*/ comments are
arguably more portable. // comments can also cause problems in
Usenet posts; implicit line wrapping can introduce syntax errors.

(Most people here in comp.lang.c already know this stuff; I'm posting
it mostly for the benefit of those in alt.folklore.computers and
comp.programming, to which this thread is cross-posted.)

--
Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
From: Patrick Scheible on
BruceS <bruces42(a)hotmail.com> writes:

> On Mar 18, 11:10=A0am, Patrick Scheible <k...(a)zipcon.net> wrote:
> > Jonathan de Boyne Pollard <J.deBoynePollard-newsgro...(a)NTLWorld.COM> writ=
> es:
> >
> >
> >
> >
> >
> > > > Agreed. But note that the "its value" and "plus" comments aren't
> > > > properly terminated, so the "/*" on the "its value" line introduces a
> > > > comment that isn't terminated until the "*/" on the "one" line. The
> > > > net result is "x =3D x;"
> >
> > > Hooray! =A0At last! =A0Well spotted. =A0I've been waiting to see how lo=
> ng it
> > > took and how many would do so.
> >
> > > So not only does the mandatory comment on every line not match the
> > > apparent code, but the apparent code isn't the actual code, as a direct
> > > consequence of the mandatory comments.
> >
> > > I'm assuming that M. Shanahan either spotted this too, or would have
> > > done so.
> >
> > Lessons:
> >
> > Even a small change, like adding a comment, can introduce a bug (as
> > Barb has been saying).
> >
> > A syntax-highlighting editor can be helpful in reducing trivial errors.
> >
> > Languages in which the end of the line ends a comment (such as C++,
> > Ada, Unix shell scripts, Icon, others) reduce or contain syntax
> > errors.
>
> <OT> AIUI, C++ accepts /* */ multiline comments without artificially
> terminating said comments at the end of line. I don't have a C++
> Standard in front of me, so I can't confirm that it isn't simply an
> artifact of environments in which I've written C++, but I'm relatively
> confident that these work the same as in C. </OT>

Yes, C++ accepts such comments, but it introduced the // to end of
line style comments and that is what I am talking about.

> According to The C Standard, 6.4.9p2, C allows comments that *do*
> automatically terminate at the end of the line, just as this style of
> comment works in C++.

C allows that now? I knew several compilers accept it,
I didn't know it was part of the standard.

-- Patrick
From: BruceS on
On Mar 18, 2:10 pm, Patrick Scheible <k...(a)zipcon.net> wrote:
> BruceS <bruce...(a)hotmail.com> writes:
> > On Mar 18, 11:10=A0am, Patrick Scheible <k...(a)zipcon.net> wrote:
> > > Jonathan de Boyne Pollard <J.deBoynePollard-newsgro...(a)NTLWorld.COM> writ=
> > es:
>
> > > > > Agreed. But note that the "its value" and "plus" comments aren't
> > > > > properly terminated, so the "/*" on the "its value" line introduces a
> > > > > comment that isn't terminated until the "*/" on the "one" line. The
> > > > > net result is "x =3D x;"
>
> > > > Hooray! =A0At last! =A0Well spotted. =A0I've been waiting to see how lo=
> > ng it
> > > > took and how many would do so.
>
> > > > So not only does the mandatory comment on every line not match the
> > > > apparent code, but the apparent code isn't the actual code, as a direct
> > > > consequence of the mandatory comments.
>
> > > > I'm assuming that M. Shanahan either spotted this too, or would have
> > > > done so.
>
> > > Lessons:
>
> > > Even a small change, like adding a comment, can introduce a bug (as
> > > Barb has been saying).
>
> > > A syntax-highlighting editor can be helpful in reducing trivial errors.
>
> > > Languages in which the end of the line ends a comment (such as C++,
> > > Ada, Unix shell scripts, Icon, others) reduce or contain syntax
> > > errors.
>
> > <OT> AIUI, C++ accepts /* */ multiline comments without artificially
> > terminating said comments at the end of line.  I don't have a C++
> > Standard in front of me, so I can't confirm that it isn't simply an
> > artifact of environments in which I've written C++, but I'm relatively
> > confident that these work the same as in C. </OT>
>
> Yes, C++ accepts such comments, but it introduced the // to end of
> line style comments and that is what I am talking about.
>
> > According to The C Standard, 6.4.9p2, C allows comments that *do*
> > automatically terminate at the end of the line, just as this style of
> > comment works in C++.  
>
> C allows that now?  I knew several compilers accept it,
> I didn't know it was part of the standard.

Yes, it's part of the C99 standard. The smiley was because "The
Standard" can refer to either the old C99 standard or the older C89
standard, depending on who's talking. IMO, this was a very useful
addition to the language. I've been using these comments for some
time, either as extensions to the standard or as part of the standard
for a language not quite C.
From: BruceS on
On Mar 18, 1:43 pm, Keith Thompson <ks...(a)mib.org> wrote:
> BruceS <bruce...(a)hotmail.com> writes:
>
> [...]
>
> > <OT> AIUI, C++ accepts /* */ multiline comments without artificially
> > terminating said comments at the end of line.  I don't have a C++
> > Standard in front of me, so I can't confirm that it isn't simply an
> > artifact of environments in which I've written C++, but I'm relatively
> > confident that these work the same as in C. </OT>
>
> In both C and C++, a comment that begins with /* is not
> "artificially" terminated at the end of the line.  Instead, it's
> "artificially" terminated by the next */.  (In other words, I'm
> not sure what's so artificial about it.)

"Artificially" may have been a poor choice of word. "Automatically"?
I was simply pointing out that both languages have the multiline
comment form that presented the misleading effect.

> > According to The C Standard, 6.4.9p2, C allows comments that *do*
> > automatically terminate at the end of the line, just as this style of
> > comment works in C++.
>
> [...]
>
> Yes, both C and C++ now permit comments introduced by // and
> terminated by the end of the line.  These were introduced in BCPL,
> one of C's distant ancestors from the 1960s.  But they were dropped
> from C, and only reintroduced by the 1999 ISO C standard (which
> superseded the 1990 ISO C standard, which itself superseded the
> de facto standard of Kernighan & Ritchie's book).  C++ has always
> supported // comments.
>
> Today, most C compilers fully support at least the C90 standard,
> but only a subset of the C99 standard.  // comments are very widely
> supported.  On the other hand, they can be rejected if you choose
> to  invoke your C compiler in a strict C90-conforming mode, or if
> you're using a sufficiently old compiler, so /*...*/ comments are
> arguably more portable.  // comments can also cause problems in
> Usenet posts; implicit line wrapping can introduce syntax errors.
>
> (Most people here in comp.lang.c already know this stuff; I'm posting
> it mostly for the benefit of those in alt.folklore.computers and
> comp.programming, to which this thread is cross-posted.)

You've made clear what I was pointing out less directly. The lack
of // comments is only when strictly adhering to the C90 (I keep
calling it "C89"; are the two terms equivalent or am I just getting it
wrong?) standard. Patrick's point is well taken, that these auto-
terminating comments can help avoid certain errors. Of course, that
would also avoid some of the humor in the early post.
From: Mensanator on
On Mar 18, 2:43 pm, Keith Thompson <ks...(a)mib.org> wrote:
> BruceS <bruce...(a)hotmail.com> writes:
>
> [...]
>
> > <OT> AIUI, C++ accepts /* */ multiline comments without artificially
> > terminating said comments at the end of line.  I don't have a C++
> > Standard in front of me, so I can't confirm that it isn't simply an
> > artifact of environments in which I've written C++, but I'm relatively
> > confident that these work the same as in C. </OT>
>
> In both C and C++, a comment that begins with /* is not
> "artificially" terminated at the end of the line.  Instead, it's
> "artificially" terminated by the next */.  (In other words, I'm
> not sure what's so artificial about it.)
>
> > According to The C Standard, 6.4.9p2, C allows comments that *do*
> > automatically terminate at the end of the line, just as this style of
> > comment works in C++.
>
> [...]
>
> Yes, both C and C++ now permit comments introduced by // and
> terminated by the end of the line.  These were introduced in BCPL,
> one of C's distant ancestors from the 1960s.  But they were dropped
> from C, and only reintroduced by the 1999 ISO C standard (which
> superseded the 1990 ISO C standard, which itself superseded the
> de facto standard of Kernighan & Ritchie's book).  C++ has always
> supported // comments.
>
> Today, most C compilers fully support at least the C90 standard,
> but only a subset of the C99 standard.  // comments are very widely
> supported.  On the other hand, they can be rejected if you choose
> to  invoke your C compiler in a strict C90-conforming mode, or if
> you're using a sufficiently old compiler, so /*...*/ comments are
> arguably more portable.  // comments can also cause problems in
> Usenet posts; implicit line wrapping can introduce syntax errors.
>
> (Most people here in comp.lang.c already know this stuff; I'm posting
> it mostly for the benefit of those in alt.folklore.computers

Hey! Some of us folklorists actually DO know how to program.

> and
> comp.programming, to which this thread is cross-posted.)
>
> --
> Keith Thompson (The_Other_Keith) ks...(a)mib.org  <http://www.ghoti.net/~kst>
> Nokia
> "We must do something.  This is something.  Therefore, we must do this."
>     -- Antony Jay and Jonathan Lynn, "Yes Minister"

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Prev: System Calls
Next: Warning to newbies