Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coding style checker for C

Tags:

I'm working for a company that has strict coding style guidelines but no automatic tool to validate them. I've looked around and the only tools I could find were lint like tools that seem to be aimed at verifying what the code does, and preventing bugs and not at making sure the coding style is correct.

What tool should we use, if at all?

NOTE: I'm looking for something for C code, although something that works for C++ would be good as well.

like image 668
elifiner Avatar asked Jan 04 '09 16:01

elifiner


1 Answers

The traditional beautifier indent, available on every Unix machine. The version found on some is GNU indent, which can be compiled and installed on every machine. GNU indent can read a set of rules from the file ~/.indent.pro, for instance:

--original --dont-format-first-column-comments --no-blank-lines-after-commas --parameter-indentation 8 --indent-level 8 --line-length 85 --no-space-after-parentheses --no-comment-delimiters-on-blank-lines  

So, just running indent before commiting guarantees uniformity of the presentation. If you want to enforce it, define a pre-commit hook in the Version Control System you use, which will run indent and refuse the commit if the committed version differs from what indent produces.

like image 159
bortzmeyer Avatar answered Oct 20 '22 03:10

bortzmeyer