Linux 内核模块编译消灭告警

ISO C90 forbids mixed declarations and codethis

由于 变量定义以前任何一条非变量定义的语句(注意:语句是会带分号的)都会引发这个警告!将非变量的定义移到变量定义以后 便可。spa

好比:prototype

int a;code

a=a+1;cmd

int b;it

改成:io

int a;function

int b;变量

a=a+1;module

便可。

-------------------------------------------------------------

function declaration isn’t a prototype

#include 
#include 
#include 
#include 
static int hello_init_module(void)
{
    printk("Hello, world - this is the kernel speaking\n");
    return 0;
}
/* Cleanup - undid whatever init_module did */
static void hello_cleanup_module(void)
{
    printk("Short is the life of a kernel module\n");
}
module_init(hello_init_module);
module_exit(hello_cleanup_module);
上面代码是内核中的一个模块, 若是 static int hello_init_module(void)  括号里面没有加void就会出现此警告。

-------------------------------------------------------------

backslash and newline separated by space

backslash and newline separated by space”
反斜杠和换行为空格所分隔”

#define NIPQUAD(addr)\
  ((unsigned char *)&addr)[0],\
  ((unsigned char *)&addr)[1],\
  ((unsigned char *)&addr)[2],\
  ((unsigned char *)&addr)[3]

相似这个,反斜杠后面不能有空格

 

-------------------------------------------------------------

statement with no effect

 int i=0;
        *n1=0;
        *n2=0;
        for(i;i<strlen(cmds);++i)
        {
                if(*(cmds+i) ==' ')
                {
                        *n1=++i;
                        break;
                }
        }

开头定义了变量,在循环内部就不须要在定义了

 

 

未完待续....

相关文章
相关标签/搜索