I'm well aware of function prototypes, this error seems to be a function declaration error, which means I'm really bewildered as to why I'm see this warning and thus error.
It's almost like gcc completely ignores my function prototype. Is this a compiler bug?
In the interest of brevity, I did not declare this function in a separate header file, though it should make no difference.
gcc output:
$ gcc -Wall -std=c99 -pedantic primefactors.c
primefactors.c: In function ‘main’:
primefactors.c:8:5: warning: implicit declaration of function ‘largestprime’ [-Wimplicit-function-declaration]
primefactors.c: At top level:
primefactors.c:12:6: error: conflicting types for ‘largestprime’
primefactors.c:8:20: note: previous implicit declaration of ‘largestprime’ was here
code:
#include <stdio.h>
#include <math.h>
long largetsprime(long);
int main()
{
printf("%d\n", largestprime(600851475143));
return 0;
}
long largestprime(long num)
{
int highest;
int mid = sqrt(num);
for (int i = 2; i < mid; i++) {
if (mid % i == 0) {
if (i % 1 == 0 && i % i == 0)
highest = i;
}
}
return highest;
}