Topic: Third Comment Type
Author: rk <rational.lampoon@gmail.com>
Date: Tue, 26 Jan 2010 16:09:28 CST Raw View
I was testing some code when it struck me that I'm doing some work
which the compiler can easily do: commenting out and uncommenting
logical blocks of code.
Anonymous blocks, if/else, switch, for/while, struct/class, and whole
functions could be commented out by marking them on one line, without
the user having to scroll and find the logical end.
e.g. (proposal using "//**", but it could be something else)
//**for(int i=0, i<length; ++i)
{
// stuff ...
}
No need to put anything after the closing brace. Nothing
revolutionary, but saves a bit of tedious navigation, and I think it
wouldn't be very hard for a compiler hacker.
RFC, & thanks for reading.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Rodrigo <rodrigorivascosta@gmail.com>
Date: Wed, 27 Jan 2010 22:02:19 CST Raw View
On 26 ene, 23:09, rk <rational.lamp...@gmail.com> wrote:
Well, the problem is that in order to know where the block ends, it
has to have a mostly correct structure.
If the syntax is correct you may easily disable it adding "if (0)"
e.g.
if (0) for(int i=0, i<length; ++i)
{
// stuff ...
}
That does nothing!
Regards.
Rodrigo.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Kenneth 'Bessarion' Boyd" <zaimoni@zaimoni.com>
Date: Sun, 31 Jan 2010 21:21:19 CST Raw View
On Jan 26, 4:09 pm, rk <rational.lamp...@gmail.com> wrote:
> I was testing some code when it struck me that I'm doing some work
> which the compiler can easily do: commenting out and uncommenting
> logical blocks of code.
>
> Anonymous blocks, if/else, switch, for/while, struct/class, and whole
> functions could be commented out by marking them on one line, without
> the user having to scroll and find the logical end.
>
> e.g. (proposal using "//**", but it could be something else)
>
> //**for(int i=0, i<length; ++i)
> {
> // stuff ...
> }
>
> No need to put anything after the closing brace. Nothing
> revolutionary, but saves a bit of tedious navigation, and I think it
> wouldn't be very hard for a compiler hacker.
As mentioned before, the if (0) prefix approach will work for the
simple cases (I haven't checked for corner cases where it would cause
a syntax error).
I'm having problems visualizing how to implement this type of
comment. (Comments are whitespace, so this is a preprocessor
adjustment rather than a compiler adjustment.) Consider this toy
example
#if 1
//**for(int i=0, i<length; ++i)
{
#else
for(int i=0, i<length-1; ++i)
{
#endif
}
Comment flushing to whitespace happens before conditional
preprocessing in reasonably standard-compliant preprocessors, so if
the source code is otherwise correct this will comment out the entire
file past the start of the comment. [/* */ comments don't have this
problem because they explicitly do not try to nest: /* /* */ still
terminates at */ . Brace blocks {} do nest.]
By comparison,
#if 1
//**for(int i=0, i<length; ++i)
#else
for(int i=0, i<length-1; ++i)
#endif
{
}
looks like it should terminate (assuming that the new comment format
picks up on the {} at all, instead of being malformed by the #else.)
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: rk <rational.lampoon@gmail.com>
Date: Mon, 1 Feb 2010 11:37:49 CST Raw View
On Jan 27, 9:02 pm, Rodrigo <rodrigorivasco...@gmail.com> wrote:
> On 26 ene, 23:09, rk <rational.lamp...@gmail.com> wrote:
>
> Well, the problem is that in order to know where the block ends, it
> has to have a mostly correct structure.
> If the syntax is correct you may easily disable it adding "if (0)"
>
> e.g.
>
> if (0) for(int i=0, i<length; ++i)
> {
> // stuff ...
> }
>
> That does nothing!
>
> Regards.
> Rodrigo.
Yes, the structure would be mostly correct (may not be compilable or
link) but would have the closing brace where required. The if(0) works
in the example I gave, but not on anything global like functions or
classes.
As for the preprocessor issue brought up by Kenneth 'Bessarion' Boyd,
I don't really see the point in using this comment mark if you're
already using macros to conditionally discard entire blocks. An #if
1 ... #endif around the for loop would suffice.
Thanks
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]