函數abs的隱式聲明 - gcc-5.1.0 Implicit declaration of function abs - gcc-5.1.0

The abs() function is declared in <stdlib.h> which you've not included. abs()函數在<stdlib.h>聲明,你沒有包含它。

fabs() function is declared in <math.h>

 

函數abs的隱式聲明 - gcc-5.1.0

Implicit declaration of function abs - gcc-5.1.0

Compiling the following code using gcc-5.1.0 produces a warning: 使用gcc-5.1.0編譯以下代碼會產生警告:

warning: implicit declaration of function ‘abs’ [-Wimplicit-function-declaration]

Code: 碼:

#include <stdio.h>
#include <math.h>

int main (void)
{
  printf ("%d\n", abs (-1));

  return 0;
}

I have compiled the same code with gcc-4.9.2 and it's not producing any warning. 我用gcc-4.9.2編譯了相同的代碼,並沒有產生任何警告。

2 個回覆

The abs() function is declared in <stdlib.h> which you've not included. abs()函數在<stdlib.h>聲明,你沒有包含它。

GCC 4.9.2 didn't complain because the default compilation mode was C89/C90 ( -std=gnu89 ) and functions did not need to be declared before being used in C89 as long as they returned an int , but the default compilation mode was changed to C11 ( -stdd=gnu11 ) in GCC 5.1.0 (see the release notes ) and in C11 functions must be declared (or defined) before they are used. GCC 4.9.2沒有抱怨,因爲默認編譯模式是C89 / C90( -std=gnu89 ),並且只要它們返回一個int ,就不需要在C89中使用之前聲明函數,但默認的編譯模式是在GCC 5.1.0中更改爲C11( -stdd=gnu11 )(參見發行說明 ),在使用之前必須聲明(或定義)C11函數。

Try to include the <stdlib.h> in your code. 嘗試在代碼中包含<stdlib.h> 。 The abs() function is defined inside the <stdlib.h> abs()函數在<stdlib.h>定義

使用gcc編譯器隱式int和隱式聲明函數 - implicit int and implicit declaration of functions with gcc compiler

我讀了c99標準: 但是當我嘗試使用-pedantic在c99模式下使用gcc編譯器編譯此代碼時 我期待2個錯誤,但我只收到2個警告: 它們不應該是c99中的錯誤嗎? http://gcc.gnu.org/c99status.html在這兩種情況下都寫了“完成”。 ...

 2012-06-23 16:25:07  3  2144   cc99 
函數的隱式聲明 - Implicit declaration of functions

我從isdigit和isalpha函數中收到此錯誤 我的代碼是: 我如何擺脫這些警告? ...

 2014-02-08 01:43:16  1  5567   clinux 
函數的隱式聲明 - implicit declaration of function

當不包含正確的頭文件時,GCC通常會發出此警告。 此鏈接-&gt; www.network-theory.co.uk/docs/gccintro/gccintro_19.html說,因爲函數聲明是隱式的(而不是通過標頭顯式聲明的),所以實際上可能會將錯誤的參數類型傳遞給函數,結果不正確。 我 ...

 2011-06-27 03:51:19  2  2258   cgcccompiler-constructiongcc-warning 
函數的隱式聲明sbrk() - Implicit Declaration of Function sbrk( )

我正在嘗試創建自己的malloc函數,但尚未完成。 這是我的代碼的相關部分: mymalloc.h : mymalloc.c 在sbrk(sizeof(tmp)); 在mymalloc.c一部分中,我得到了"Implicit declaration of functio ...

 2017-12-25 07:42:33  1  628   c 
函數“ wiringPilSR”的隱式聲明 - implicit declaration of function 'wiringPilSR'

我正在嘗試使用connectioningPI的wiringPilSR將中斷附加到引腳。 我的代碼如下所示: 當我嘗試在Geany中構建代碼時,出現警告“ implicit declaration of function 'wiringPilSR' ”和錯誤“ undefined ref ...

 2017-02-25 22:22:37  1  268   craspberry-pigeanywiringpiimplicit-declaration 
錯誤:函數的隱式聲明 - Error: Implicit declaration of function

我下面的代碼有錯誤。 它說函數的隱式聲明在C99中無效。 我不太確定如何解決此問題。 ...

 2014-10-20 08:50:39  1  2006   objective-ccc99 
mkstemp函數的隱式聲明 - mkstemp implicit declaration of function

我的功能mkstemp()有問題。 cygwin上的GCC編譯器會生成警告: GCC標誌: -std=c99 -Wall 包括: ...

 2014-07-15 12:19:05  1  962   ccygwinmkstemp 
函數x的隱式聲明 - Implicit declaration of function x

我很清楚函數原型,這個錯誤似乎是一個函數聲明錯誤,這意味着我真的很困惑,爲什麼我看到這個警告,從而錯誤。 這幾乎就像gcc完全忽略了我的函數原型。 這是編譯器錯誤嗎? 爲了簡潔起見,我沒有在單獨的頭文件中聲明此函數,儘管它應該沒有區別。 gcc輸出: 碼: ...

 2013-07-24 16:45:53  4  4440   calgorithmprime-factoring  
函數fseeko的隱式聲明 - Implicit declaration of function fseeko

我正在嘗試將fseeko函數與GCC編譯器結合使用,以處理C中大於4GiB的文件。現在,一切正常,我能夠處理超過4GiB的文件,但GCC一直在抱怨fseeko函數是隱式聲明的。 這是生成此消息的源代碼的最小工作示例: 我在任何地方都找不到要解決此警告的標頭。 GCC給出的確切警告是: ...

 2016-11-23 17:20:52  1  765   clarge-filesfseek 
10 函數的隱式聲明 [重複] - Implict Decleration of Function [duplicate]

這個問題在這裏已經有了答案: 警告:函數的隱式聲明(9 個回答) 11 個月前關閉。 首先我不得不說我的大腦因 ...

 2020-10-05 14:52:11  3  83   cfunctionimplicit 


 
 
https://stackoom.com/cn_en/question/23m3i
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章