Coder Social home page Coder Social logo

Understand C++: Ignore comments about guardonce HOT 3 OPEN

cgmb avatar cgmb commented on June 30, 2024
Understand C++: Ignore comments

from guardonce.

Comments (3)

cgmb avatar cgmb commented on June 30, 2024

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

e.g.

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

from guardonce.

cgmb avatar cgmb commented on June 30, 2024

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

from guardonce.

cgmb avatar cgmb commented on June 30, 2024

I should probably mention that the 'smart parser' was dropped in 3af39a7. 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.

from guardonce.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.