본문 바로가기

c,c++

Implicit declaration of function

gcc로 컴파일하는 과정에서 Implicit declaration of function 메시지가 떴다.

위의 메시지는 prototype 선언 없이 함수를 사용하려고 할 때 뜬다고 한다.

 

예시로 다음과 같이 코드를 작성하면 Implicit declaration of function message가 뜬다.

#include <stdio.h>

/*char ntoc(int a); // <- prototype 주석 처리 */

int main(){
    printf("%c\n",ntoc(3));
    return 0;
}

char ntoc(int a){
    return (a%10) + '0';
}

-------

$ gcc -o main main.c
main.c: In function ‘main’:
main.c:4:19: warning: implicit declaration of function ‘ntoc’ [-Wimplicit-function-declaration]
    4 |     printf("%c\n",ntoc(3));
      |                   ^~~~
main.c: At top level:
main.c:8:6: error: conflicting types for ‘ntoc’
    8 | char ntoc(int a){
      |      ^~~~
main.c:4:19: note: previous implicit declaration of ‘ntoc’ was here
    4 |     printf("%c\n",ntoc(3));
      |                   ^~~~

 

 

 

 

참고 : 
https://stackoverflow.com/questions/8440816/warning-implicit-declaration-of-function

 

'c,c++' 카테고리의 다른 글

함수포인터 / 함수 객체 / 람다 간단 정리  (0) 2021.09.27
printf vs puts  (0) 2021.07.11