guardonce icon indicating copy to clipboard operation
guardonce copied to clipboard

Understand C++: Ignore comments

Open cgmb opened this issue 12 years ago • 3 comments

When searching through files, anything within comment blocks should be ignored as irrelevant.

cgmb avatar Aug 16 '13 03:08 cgmb

It seems that C gives you a surprising amount of flexibility in placing comments.

e.g.

/* comment */ # /* comment */ include /* comment */ <stdio.h> // comment

cgmb avatar Jul 27 '16 05:07 cgmb

It can be even worse...

/*
comment */ # /* comment */ include /* comment */ <stdio.h> /* comment
*/

In the smart parser, I've been stripping comments from the beginning and ends of the lines, because they're usually irrelevant once the code is changed. Unfortunately, it's a little unclear what to do when they span multiple lines. I suspect I should leave them alone. Multi-line comments are probably less likely to be specific to the line I'm removing than single-line comments are.

I've never actually seen this sort of code, but I could imagine it:

/* Copyright <Year> <Author>
   <License>
*/ #pragma once

cgmb avatar Aug 04 '16 00:08 cgmb

I should probably mention that the 'smart parser' was dropped in 3af39a7107029265d2ab2887f47823af41f3c15d. Not sure if or when I'll work on it again. It would certainly handle a few more weird cases, like the horror above, but I would basically only find out if it was worth the (significant) effort after the fact.

cgmb avatar Feb 07 '17 21:02 cgmb