Here's a function calculating the division of two numbers. All variables and functions are declared as float. However, the code below does not compile and the error message shows that "%f expects argument of type double, but argument has type int" and "implicit declaration of function 'div'" and "conflicting types for 'div'".
#include <stdio.h>
#include <assert.h>
float div(float a, float b);
int main() {
float a = 5;
float b = 8;
printf("%f divided by %f is %f \n", a, b, div(a, b));
}
float div(float a, float b) {
assert(b != 0);
return a / b;
}
The 2018 C standard discusses the standard library in clause 7. C 2018 7.1.3 1 says:
… All identifiers with external linkage in any of the following subclauses (including the future library directions) and
errnoare always reserved for use as identifiers with external linkage.
In one of the following subclauses, 7.22.6.2, div is described as a function, and hence as an identifier with external linkage.
Therefore, it is reserved for use as the name of a standard library routine, and the behavior of a program that uses it for another purpose is not defined by the C standard.
Rename your function.