我最近学会了如何编写简单的字符驱动程序,在玩这些代码时,我注意到我的C99代码中出现了很多以下的GCC警告:
warning: ISO C90 forbids mixed declarations and code
Run Code Online (Sandbox Code Playgroud)
我假设这是因为主Linux内核Makefile设置为使用非C99标准进行编译.我在附近搜索我在stackoverflow上找到了这个答案:如何使用make和编译为C99?
所以我自然在我的Makefile中尝试了以下内容:
ccflags-y := -std=gnu99
Run Code Online (Sandbox Code Playgroud)
不幸的是,这并没有使GCC警告无声.我检查了详细的输出make并验证了GCC确实-std=gnu99在最后加上了; 所以我有点困惑.
如何使用该-std=gnu99选项正确编译Linux内核模块?
编辑:
我注意到GCC输出显示了这个选项:-Wdeclaration-after-statement.这是为什么即使有-std=gnu99选项我也会得到警告?