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;
                }
        }

開頭定義了變量,在循環內部就不須要在定義了

 

 

未完待續....

相關文章
相關標籤/搜索