How to enforce C89-style variable declarations in gcc?

老子叫甜甜 提交于 2019-12-03 06:02:47

You're after the -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations and -Wdeclaration-after-statement options, as described on the gcc warnings info page. Note that these can cause a lot of noise from issues in system header files, and they're only warnings so you've got to have a policy of being keen to have a zero-warning build.

I don't believe there is a way to do what you want. The dialect of C supported by MSVC is closer to C89 than C99 (eg. it doesn't support designated initializers either); you really want something more akin to C89-with-C++-comments-and-inline-keyword.

The problem with that is that C++ comments can affect the correctness of valid C89 code. For example, the meaning of this line changes substantially:

int a = 10//* foo */2;

I'd say your best bet is to enforce C89 in your C source files, including C89-style comments. inline is probably OK, though: you can define it to __inline on gcc.

It is not Win32 that renders the code uncompilable, but the compiler. You can use GCC on Win32 and get greater cross-platform compatibility.

Another possibility is to use C++ compilation for your Win32 build; the GCC compilation will already have determined that it is valid C, and C++ compilation will generally make it stronger C too.

[edit] Another solution is to use a continuous integration server such as CruiseControl configured so that whenever the GCC platform coders check-in code, the CI server can check it out and build it using VC++ (or even apply a third-party static analysis tool) and on error e-mail the results to the user who checked in the erroneous code. This solution may be heavyweight for the original problem, but may yield many other benefits besides.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!