admin管理员组文章数量:1123407
My application is written in C99 (or rather GNU99, and I wouldn't mind going to GNU11), and I'd like to require trailing commas in structure initializers. Does GCC have a warning (turned into error through -Werror
) that I could enable? I couldn't find one.
My application is written in C99 (or rather GNU99, and I wouldn't mind going to GNU11), and I'd like to require trailing commas in structure initializers. Does GCC have a warning (turned into error through -Werror
) that I could enable? I couldn't find one.
- 2 Trailing comma has always been allowed in initializer lists. What C99 changed was just to also allow it in enum lists. – Lundin Commented 15 hours ago
- 2 Anyway this sounds like something that should be added by a code formatter/beautifier. Not really the compiler's job. – Lundin Commented 15 hours ago
1 Answer
Reset to default 1No, compiler can not require this, since presence or absence of trailing comma are not an error and cannot really lead to an error.
But you can use code formatters for this. For example, clang-format
has a special setting for it: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#inserttrailingcommas
And yes, you can install and use clang-format
without clang
.
Many text editors can run formatter automatically on save. Or you can run formatter as pre-commit hook in git.
本文标签: cRequire trailing commaStack Overflow
版权声明:本文标题:c - Require trailing comma - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736569036a1944746.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论