Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 929
wakwakwak99 Avatar asked Apr 11 '15 12:04

wakwakwak99


People also ask

How do you fix an implicit function declaration?

Solution of Implicit declaration of function 1) If you are using pre-defined function then it is very likely that you haven't included the header file related to that function. Include the header file in which that function is defined.

How do you get rid of implicit declaration warning?

In C90, this error can be removed just by declaring your function before the main function. In the case of C99, you can skip the declaration but it will give us a small warning and it can be ignored but the definition of the function is important.

What is implicit declaration error?

Such an 'implicit declaration' is really an oversight or error by the programmer, because the C compiler needs to know about the types of the parameters and return value to correctly allocate them on the stack.

What does implicit function declaration mean?

If a name appears in a program and is not explicitly declared, it is implicitly declared. The scope of an implicit declaration is determined as if the name were declared in a DECLARE statement immediately following the PROCEDURE statement of the external procedure in which the name is used.


1 Answers

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.

like image 84
tux3 Avatar answered Sep 20 '22 02:09

tux3