저는 함수 프로토 타입에 대해 잘 알고 있습니다.이 오류는 함수 선언 오류 인 것 같습니다. 이는 내가이 경고와 오류를 보게 된 이유에 대해 정말 당황 스럽다는 것을 의미합니다.함수의 암시 적 선언 x
gcc가 내 함수 프로토 타입을 완전히 무시한 것 같습니다. 이것은 컴파일러 버그입니까?
간결함을 위해 별도의 헤더 파일에서이 함수를 선언하지 않았지만 아무런 차이가 없어야합니다.
GCC 출력 :
$ 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
코드 :
#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;
}
의견은 downvote와 관련하여 좋을 것입니다. – TheBlueCat
왜 아래로 투표합니까? – haccks