Topic: Nested comments


Author: celtschk@web.de (Christopher Eltschka)
Date: Tue, 15 Oct 2002 19:37:37 +0000 (UTC)
Raw View
Gennaro Prota <gennaro_prota@yahoo.com> writes:

> On 27 Aug 2002 21:10:04 GMT, Allan_W@my-dejanews.com (Allan W) wrote:
>
> >Gennaro Prota <gennaro_prota@yahoo.com> wrote
> >> Compile-time detection :-)
> >>
> >> struct has_nested_comments {
> >>  static const bool value = /*  /* */
> >>                  1? false : // */
> >>                  true;
> >> };
> >>
> >> Of course it relies, like your solution, on that
> >>
> >>     // */
> >>
> >> at the end of a line, whose behavior for compilers that allow nested
> >> comments depends on what the implementer decided to do.
> >
> >    struct has_nested_comments {
> >        static const bool value = /* /* */ false /*/ true /* */;
> >    };
> >
>
>
> Yes, it would be a real pearl for a feature-detection suite (uh?) :-)
> But there's an error because (unless the implementer opted for some
> very odd rule) when comments nest the /* just after the literal
> "false" starts another comment.

struct has_nested_comments
{
  static const bool value = !(/*/*/0*/**/1);
};

>
> I hope others will not think we're taking it seriously! :-)

Why? I'm *seriouly* having fun with it :-)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: hyrosen@mail.com (Hyman Rosen)
Date: Tue, 15 Oct 2002 23:39:03 +0000 (UTC)
Raw View
Christopher Eltschka wrote:
> struct has_nested_comments
> {
>   static const bool value = !(/*/*/0*/**/1);
> };

The sense is reversed; it should be

struct has_nested_comments { static const bool value = /*/*/0*/**/1; };

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Allan_W@my-dejanews.com (Allan W)
Date: Mon, 26 Aug 2002 18:56:28 CST
Raw View
> Submitted by "Sachin Garg" to comp.lang.c++:
> > Are nested /**/ comments allowed in standard C++

> "Andreas K   h   ri" <ak@freeshell.org.REMOVE> wrote
> No.
>     "The characters /* start a comment, which terminates with
>     the characters */. These comments do not nest."

"Sachin Garg" <schngrg@yahoo.com> wrote
> Thanx, actually some compilers allow nesting, others don't, so I
> decided to check out what was the std way.

    int main() {
        std::cout << "This compiler handles comments in a ";
        /*
          /* */
        if (false) // */
            std::cout << "NON-";
        std::cout << "standard way!\n";
    }

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Gennaro Prota <gennaro_prota@yahoo.com>
Date: Tue, 27 Aug 2002 06:43:57 CST
Raw View
On Mon, 26 Aug 2002 18:56:28 CST, Allan_W@my-dejanews.com (Allan W)
wrote:

>
>    int main() {
>        std::cout << "This compiler handles comments in a ";
>        /*
>          /* */
>        if (false) // */
>            std::cout << "NON-";
>        std::cout << "standard way!\n";
>    }
>

Compile-time detection :-)

struct has_nested_comments {
 static const bool value = /*  /* */
                 1? false : // */
                 true;
};

Of course it relies, like your solution, on that

    // */

at the end of a line, whose behavior for compilers that allow nested
comments depends on what the implementer decided to do.


Genny.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Raghu B.Uppalli" <rbuppall@mcnc.org>
Date: 27 Aug 2002 18:50:01 GMT
Raw View
Sachin Garg wrote:

> Hi,
>
> Are nested /**/ comments allowed in standard C++
>
> /*
> ....
>    /*
>         .....
>         .....
>     */
> .....
> */

No. But if you need to do nested commenting,a  common trick is to use teh
 preprocessor directives.

Eg:

#if 0
/* ,,,,,,,,,,,,
dksaldka
  /*
        jjdasldas
  */
lasldsa
*/
#endif

Everything in here is a comment. It is a little obscure, but helps if you
are testing stuff and dont want to mess up with your existing comments.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Allan_W@my-dejanews.com (Allan W)
Date: Tue, 27 Aug 2002 16:08:42 CST
Raw View
> Allan_W@my-dejanews.com (Allan W) wrote:
> >
> >    int main() {
> >        std::cout << "This compiler handles comments in a ";
> >        /*
> >          /* */
> >        if (false) // */
> >            std::cout << "NON-";
> >        std::cout << "standard way!\n";
> >    }
> >

Gennaro Prota <gennaro_prota@yahoo.com> wrote
> Compile-time detection :-)
>
> struct has_nested_comments {
>  static const bool value = /*  /* */
>                  1? false : // */
>                  true;
> };
>
> Of course it relies, like your solution, on that
>
>     // */
>
> at the end of a line, whose behavior for compilers that allow nested
> comments depends on what the implementer decided to do.

    struct has_nested_comments {
        static const bool value = /* /* */ false /*/ true /* */;
    };

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Gennaro Prota <gennaro_prota@yahoo.com>
Date: Wed, 28 Aug 2002 03:41:11 CST
Raw View
On 27 Aug 2002 21:10:04 GMT, Allan_W@my-dejanews.com (Allan W) wrote:

>Gennaro Prota <gennaro_prota@yahoo.com> wrote
>> Compile-time detection :-)
>>
>> struct has_nested_comments {
>>  static const bool value = /*  /* */
>>                  1? false : // */
>>                  true;
>> };
>>
>> Of course it relies, like your solution, on that
>>
>>     // */
>>
>> at the end of a line, whose behavior for compilers that allow nested
>> comments depends on what the implementer decided to do.
>
>    struct has_nested_comments {
>        static const bool value = /* /* */ false /*/ true /* */;
>    };
>


Yes, it would be a real pearl for a feature-detection suite (uh?) :-)
But there's an error because (unless the implementer opted for some
very odd rule) when comments nest the /* just after the literal
"false" starts another comment.

I hope others will not think we're taking it seriously! :-)


Genny.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Sachin Garg" <schngrg@yahoo.com>
Date: Mon, 26 Aug 2002 00:27:52 GMT
Raw View
Hi,

Are nested /**/ comments allowed in standard C++

/*
....
   /*
        .....
        .....
    */
.....
*/

Sachin Garg [India]
http://sachingarg.cjb.net
http://sachingarg.go.to



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Chris Connett" <chrisM84000@hotMmail.com>
Date: Mon, 26 Aug 2002 02:20:58 GMT
Raw View
"Sachin Garg" <schngrg@yahoo.com> wrote in message
news:akbc8s$mk$1@newsreader.mailgate.org...
> Hi,
>
> Are nested /**/ comments allowed in standard C++
>
> /*
> ....
>    /*
>         .....
>         .....
>     */
> .....
> */
>
> Sachin Garg [India]

Not really. Once inside the first comment, the second comment-open-symbol is
not read to create nesting. In your example the first */ (closer) pairs up
with the first opener, for a complete comment, but after that its
non-comment again.

/* this area is a comment
..... this area is a comment
   /* this area is a comment
        ..... this area is a comment
        ..... this area is a comment
    */ this area is NOT a comment
...... this area is a not comment
*/ <--- you'll likely get a complier error for bad syntax


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Andreas =?iso-8859-1?Q?K=E4h=E4ri?= <ak@freeshell.org.REMOVE>
Date: Mon, 26 Aug 2002 05:28:49 GMT
Raw View
Submitted by "Sachin Garg" to comp.lang.c++:
> Hi,
>=20
> Are nested /**/ comments allowed in standard C++
>=20
> /*
> ....
>    /*
>         .....
>         .....
>     */
> .....
> */

No.

    "The characters /* start a comment, which terminates with
    the characters */. These comments do not nest."


--=20
Andreas K=E4h=E4ri
--------------------------------------------------------------
Stable, secure, clean, free:  www.netbsd.org

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Sachin Garg" <schngrg@yahoo.com>
Date: Mon, 26 Aug 2002 17:19:46 GMT
Raw View
"Andreas K   h   ri" <ak@freeshell.org.REMOVE> wrote in message
news:slrnamj2bc.vs.ak@otaku.freeshell.org...
Submitted by "Sachin Garg" to comp.lang.c++:
> Are nested /**/ comments allowed in standard C++
No.

    "The characters /* start a comment, which terminates with
    the characters */. These comments do not nest."
Hi,

Thanx, actually some compilers allow nesting, others don't, so I
decided to check out what was the std way.

Sachin Garg [India]
http://sachingarg.cjb.net
http://sachingarg.go.to




---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Micah Cowan <micah@cowan.name>
Date: Mon, 26 Aug 2002 17:19:46 GMT
Raw View
"Sachin Garg" <schngrg@yahoo.com> writes:

> Hi,
>
> Are nested /**/ comments allowed in standard C++
>
> /*
> ....
>    /*
>         .....
>         .....
>     */
> .....
> */

No. The comment will terminate with the first */. Many compilers will
detect this and issue a warning.

-Micah

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: kanze@gabi-soft.de (James Kanze)
Date: Mon, 26 Aug 2002 18:33:21 GMT
Raw View
Andreas ?iso-8859-1?Q?K??i? <ak@freeshell.org.REMOVE> wrote in message
news:<slrnamj2bc.vs.ak@otaku.freeshell.org>...
> Submitted by "Sachin Garg" to comp.lang.c++:

> > Are nested /**/ comments allowed in standard C++

> > /*
> > ....
> >    /*
> >         .....
> >         .....
> >     */
> > .....
> > */

> No.

>     "The characters /* start a comment, which terminates with
>     the characters */. These comments do not nest."

On the other hand, /* ... */ comments out any //, and vice versa.

Perhaps more usefully, a // doesn't start a new comment (requiring a new
end of line).  This is very useful when commenting out code:

    //  ...
    //  ...
    //  //  Previous comment
    //  ...

I'm sure any editor worth its salt will have commands for inserting and
removing such text from the beginning of a line. ('s:^://  :' in vi,
with 's:^....::' to remove.)

--
James Kanze                           mailto:jkanze@caicheuvreux.com
Conseils en informatique orient   e objet/
                    Beratung in objektorientierter Datenverarbeitung

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]