abs 'implicit declaration…' error after including math.h

倾然丶 夕夏残阳落幕 提交于 2019-12-05 16:05:22

问题


I used the abs() function and I added #include <math.h> at the top of code. But I keep getting this error:

hello.c:20:11: warning: implicit declaration of function 'abs' is invalid in C99
[-Wimplicit-function-declaration]
      int a = abs(arrOfHour[i] - hour) * 60 + minute;
              ^

I'm using LLVM compiler.

Why does this error occurs even though I have included math.h?


回答1:


I'm going to quote straight from the docs : "Prototypes for abs, labs and llabs are in stdlib.h"

As a rule of thumb the mathematical functions that operate on floating point numbers are in math.h, and the ones that operate on integers are in stdlib.h.

There's a pretty good Wikipedia article on C mathematical functions if you need more information.



来源:https://stackoverflow.com/questions/29577833/abs-implicit-declaration-error-after-including-math-h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!