6

I am searching for free Linux tool that can analyze C and C++ code of my program and return style improvement suggestions. I would like to check against coding standards like variable naming, capitalization, spacing, indentation, bracket placement, and so on.

  • 1
    This seems far too vague to get a good answer. For instantce, how do you expect to tell it what "good variable naming" is? If I found you a tool that insisted that all identifiers had to be made only out of the character "x", would you be happy? I don't think you have stated your requirements clearly. – Ira Baxter Jul 8 '14 at 7:09
  • 1
    @IraBaxter , for example,check google c++ style guide(I need something like this but it is book and I need program implementation). PS:There you can find variable naming.. – BrettWatts Jul 8 '14 at 7:58
  • 1
    OK, so clarify what you actually want. You want the Google book exactly? Something different? SR requires that your question be clearly answerable. – Ira Baxter Jul 8 '14 at 8:19
  • 1
    It doesn't do anything with the stupid names you give stuff, but uncrustify does most of the formatting that you are looking for. – technosaurus Dec 29 '14 at 20:07
1

If you're ok with using clang utilities you can use ClangFormat. Usually I use this to just force a certain format, but you could use the -output-replacements-xml flag to check if anything needs to be changed.

Note that this allows you to specify what a good format is by using different coding styles like llvm, Google or Mozilla standards (you can even make your own!).

| improve this answer | |
  • He's asking about coding style, not format. – Ira Baxter Sep 7 '14 at 21:08
  • @IraBaxter it certainly sounds like he's asking about the formatting, i.e. he wants to verify his program follows a certain scheme of variable naming, capitalization, spacing, indentation, bracket placement, which is exactly what clangformat does - it outputs the formats that don't follow a style you want. – DanZimm Sep 7 '14 at 21:19
  • He wants something that produces opinions. What opinions does Clangformat have about variable names? Coding standards usually refers to the way things are expressed, e.g., the Misra standards. Yes, such standards can have rules about { placement, but those are hardly the deep ones, and AFAIK, ClangFormat doesn't have an opinion, just a result. – Ira Baxter Sep 7 '14 at 23:57
  • Of course, OP is always welcome to clarify. – Ira Baxter Sep 7 '14 at 23:57
  • 2
    @IraBaxter I recognize the difference between styling and coding rules - yes clang-format applies styling. As far as I understand this is part of what the OP wants (in fact he uses both "style" and "coding standards", so both would probably help him). Nonetheless talking about opinions is fairly ambiguous. clang-format certainly outputs opinions about the code considering the styling it applies is an opinion of someone. – DanZimm Sep 8 '14 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.