C的编码样式检查器 [英] Coding style checker for C

查看:94
本文介绍了C的编码样式检查器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为一家有严格的编码风格指南,但没有自动工具验证他们的公司工作。我已经找到了,我可以找到的唯一工具是lint像工具,似乎旨在验证代码的作用,并防止错误,而不是确保编码风格是正确的。

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?

注意:我正在寻找C代码的东西,虽然有些东西适用于C ++

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

推荐答案

传统美化缩进,在每个Unix机器上都可用。某些版本中找到的版本是 GNU缩进,可以在每台计算机上进行编译和安装。 GNU缩进可以从文件〜/ .indent.pro 中读取一组规则,例如:

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.

这篇关于C的编码样式检查器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆