c 的编码风格检查器(变量名称,而不是缩进)

发布于 2024-10-27 09:16:27 字数 445 浏览 1 评论 0原文

这个问题询问编码风格检查器,但重点似乎是缩进和支架放置。 GNU indent 处理缩进(这在这个代码库中不是问题,令人惊讶的是)。

我正在使用一堆充满各种命名方案的代码:camelCaseeverythingruntogetherinlowercaseunderscores_as_separatorsSomeStructsEndWithT code> 等。

我希望能够选择一个约定,并至少自动检查新的更改是否符合约定。

有没有一个好的工具可以检查 C 中的命名?像Python的pep8检查器工具之类的东西,我不需要美化器。

谢谢。

This question asks about a coding style checker, but the focus seems to be on indentation and brace placement. GNU indent deals with indentation (which isn't a problem in this code base, amazingly enough).

I'm working with a pile of code that is full of various naming schemes: camelCase, everythingruntogetherinlowercase, underscores_as_separators, SomeStructsEndWithT, etc.

I'd like to be able to pick a convention and at least have an automatic check that new changes are in line with the convention.

Is there a good tool for checking naming in C? Something like Python's pep8 checker tool, I don't want a beautifier.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

白龙吟 2024-11-03 09:16:27

看起来 Google 的 cpplint(C++ 风格检查器)可能会被黑客入侵像我想要的那样提交检查 C。

(我仍然有兴趣知道是否有更好的检查器。)

It looks like Google's cpplint (a C++ style checker) can be hacked into submission for checking C like I want.

(I'm still interested in knowing if there are any better checkers out there.)

十秒萌定你 2024-11-03 09:16:27

这是一个非正统的选择,但如果您愿意投入半天的时间,我会选择cxref。它是一个交叉引用器,附带源代码,它有一个干净的解析器,并且不构建解析树。然而,只需几行代码,您就可以转储所有变量来检查它们,或者将它们重写为您喜欢的样式(或者如果您像我一样懒惰,而不是重写,您可以为 emacs/sed 生成替换命令)。我只设法为 Mac 构建它。

It is an unorthodox choice, but I'd go with cxref, if you are willing to put in half a days work. It is a cross referencer, comes with the source code, it has a clean parser and doesn't build a parse tree. Yet, with a few lines of code you can dump all the variables to examine them, or rewrite them to your favoured style (or if you are as lazy as I am instead of rewriting you could generate replace commands for emacs/sed). I only managed to build it for Mac.

天气好吗我好吗 2024-11-03 09:16:27

C 的编码风格检查器 中已经有很多答案

这个线程 Vera++ 可能是最有前途的,因为大多数其他建议都是格式化程序而不是验证程序。有一个关于运行 vera++ 的网页:
https://bitbucket.org/verateam/vera/wiki/Running

可从 https://bitbucket.org/verateam/ 下载维拉/下载/vera++-1.1.1.tar.gz
编译会出现一些问题:

最后,在 C++ 文件上运行它会产生如下输出(为简洁起见,省略重复错误):

../dllist.c:1: no copyright notice found
../dllist.c:4: horizontal tab used
../dllist.c:10: horizontal tab used
../dllist.c:10: closing curly bracket not in the same line or column
../dllist.c:29: horizontal tab used
../dllist.c:38: keyword 'if' not followed by a single space
../dllist.c:38: negation operator used in its short form
../dllist.c:40: horizontal tab used
../dllist.c:40: full block {} expected in the control structure
../dllist.c:42: horizontal tab used
../dllist.c:71: keyword 'if' not followed by a single space
../dllist.c:71: negation operator used in its short form
../dllist.c:72: horizontal tab used
../dllist.c:72: full block {} expected in the control structure
../dllist.c:73: horizontal tab used

This one has a number of answers already in this thread Coding style checker for C

from which Vera++ might be the most promising, since most of the other suggestions are formatters not validators. There's a webpage about running vera++ at
https://bitbucket.org/verateam/vera/wiki/Running.

There's a download from https://bitbucket.org/verateam/vera/downloads/vera++-1.1.1.tar.gz
Compiling presents a few issues:

  • sudo apt-get install libboost-dev tcl-dev
  • An include of tcl.h that should have been tcl/tcl.h
  • Need a full boost src tree, like that from http://sourceforge.net/projects/boost/files/boost/1.53.0/boost_1_53_0.tar.gz/download
  • The build command becomes something like: make BOOST_DIR=/home/fluffy/tmp/boost_1_53_0
  • vera++ needs a ~/.vera++/profiles/ but doesn't autocreate a default (it can be copied from the one in the distribution, however)

Finally, running it on a C++ file produced output like (with duplicate errors omitted for brevity):

../dllist.c:1: no copyright notice found
../dllist.c:4: horizontal tab used
../dllist.c:10: horizontal tab used
../dllist.c:10: closing curly bracket not in the same line or column
../dllist.c:29: horizontal tab used
../dllist.c:38: keyword 'if' not followed by a single space
../dllist.c:38: negation operator used in its short form
../dllist.c:40: horizontal tab used
../dllist.c:40: full block {} expected in the control structure
../dllist.c:42: horizontal tab used
../dllist.c:71: keyword 'if' not followed by a single space
../dllist.c:71: negation operator used in its short form
../dllist.c:72: horizontal tab used
../dllist.c:72: full block {} expected in the control structure
../dllist.c:73: horizontal tab used
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文