2010-03-09 74 views
1

我有一個RefTables.pc文件。C .pc文件警告

當我執行命令make,我得到這樣的警告:

RefTables.c:109: warning: type defaults to `int' in declaration of `sqlcxt' 
RefTables.c:111: warning: type defaults to `int' in declaration of `sqlcx2t' 
RefTables.c:113: warning: type defaults to `int' in declaration of `sqlbuft' 
RefTables.c:114: warning: type defaults to `int' in declaration of `sqlgs2t' 
RefTables.c:115: warning: type defaults to `int' in declaration of `sqlorat' 

如何刪除呢?

我正在使用linux & gcc編譯器。

回答

1

您可以通過指定5個違規聲明的類型來刪除警告。實際上,它們必須聲明爲無類型,默認爲C中的int(但會生成警告)。

編輯:我在Google上找到了這個聲明。

extern sqlcxt (/*_ void **, unsigned int *, struct sqlexd *, struct sqlcxp * _*/); 

函數沒有返回類型。它應該有一個。寫下如下。

extern int sqlcxt (/*_ void **, unsigned int *, struct sqlexd *, struct sqlcxp * _*/); 

或者您可以在編譯器命令行中手動聲明忽略這些警告。他們將不會再顯示。

+0

我如何刪除警告。你會更詳細地描述 。 – ambika 2010-03-09 12:35:51

0

將來,請提供一段代碼和警告,以便我們有一些上下文可供使用。否則,我們只能猜測真正的問題是什麼。

我假設sqlcxt,sqlcx2t等是函數。在沒有看到源代碼的情況下,它聽起來像是在使用它們之前沒有爲這些函數聲明這些函數。

這裏是什麼,我的意思是一個簡單的例子:

int main(void) 
{ 
    foo(); 
    return 0; 
} 

void foo(void) 
{ 
    // do something interesting 
} 

當編譯器看到在main調用foo,它沒有範圍的聲明,所以它假定foo返回int,而不是無效,並會返回類似於上面得到的警告。

如果你的函數被定義在它們被調用的同一個文件中,解決這個問題的方法有兩種。我的首選方法是定義功能在使用前:

void foo(void) 
{ 
    // do something interesting 
} 

int main(void) 
{ 
    foo(); 
    return 0; 
} 

另一種方法是調用它之前在範圍函數的聲明:

void foo(void); 

int main(void) 
{ 
    foo(); 
    return 0; 
} 

void foo(void) 
{ 
    // do something interesting 
} 

這聽起來像這些功能的一部分的數據庫API;如果是的話,應該有一個包含這些函數的聲明頭文件,並且頭部應包含在源文件:

/** foo.c */ 
#include "foo.h" 

void foo(void) 
{ 
    // do something interesting 
} 
/** end foo.c */ 

/** foo.h */ 
#ifndef FOO_H 
#define FOO_H 

void foo(void); 

#endif 
/** end foo.h */ 

/** main.c */ 
#include "foo.h" 

int main(void) 
{ 
    foo(); 
    return 0; 
} 
/** end main.c */ 

希望有所幫助。

1

這已經有一段時間,因爲我使用了Pro * C,但我認爲你可以在命令行選項添加到proc命令行

code=ANSI_C 

,這將給名爲函數的原型。

+0

感謝您的建議。 但我用Makefile&make命令來編譯。 我如何使用proc命令。 – ambika 2010-03-11 05:17:46

+0

什麼是生成文件中的.pc文件生成.c文件的命令? – 2010-03-11 08:04:52