programing

경고: 함수의 암묵적인 선언

goodcopy 2022. 8. 8. 16:02
반응형

경고: 함수의 암묵적인 선언

컴파일러(GCC)가 다음 경고를 표시합니다.

경고: 함수의 암묵적인 선언

왜 그것이 오는지 이해할 수 있도록 도와주세요.

컴파일러가 아직 선언("프로토타입")을 인식하지 못한 함수를 사용하고 있습니다.

예를 들어 다음과 같습니다.

int main()
{
    fun(2, "21"); /* The compiler has not seen the declaration. */       
    return 0;
}

int fun(int x, char *p)
{
    /* ... */
}

다음과 같이 함수를 메인 전에 직접 또는 헤더로 선언해야 합니다.

int fun(int x, char *p);

올바른 방법은 헤더에 함수 프로토타입을 선언하는 것입니다.

메인.h

#ifndef MAIN_H
#define MAIN_H

int some_main(const char *name);

#endif

메인

#include "main.h"

int main()
{
    some_main("Hello, World\n");
}

int some_main(const char *name)
{
    printf("%s", name);
}

1개의 파일로 대체 가능(main.c)

static int some_main(const char *name);

int some_main(const char *name)
{
    // do something
}

기본 기능 전에 원하는 기능을 선언해야 합니다.

#include <stdio.h>
int yourfunc(void);

int main(void) {

   yourfunc();
 }

#includes in main.c에서 #include reference를 include 목록의 맨 위에 배치합니다.예를 들어, 이것이 main.c이고, 참조된 함수가 "SSD1306_LCD"에 있다고 가정해 주세요.h"

#include "SSD1306_LCD.h"    
#include "system.h"        #include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <string.h>
#include <math.h>
#include <libpic30.h>       // http://microchip.wikidot.com/faq:74
#include <stdint.h>
#include <stdbool.h>
#include "GenericTypeDefs.h"  // This has the 'BYTE' type definition

위의 경우 "암시적 함수 선언" 오류가 생성되지는 않지만, 아래의 오류는 발생합니다.

#include "system.h"        
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <string.h>
#include <math.h>
#include <libpic30.h>       // http://microchip.wikidot.com/faq:74
#include <stdint.h>
#include <stdbool.h>
#include "GenericTypeDefs.h"     // This has the 'BYTE' type definition
#include "SSD1306_LCD.h"    

#인크루드 리스트는 완전히 같으며 순서가 다를 뿐입니다.

음, 그건 내게는 그랬다.

함수와 그 프로토타입에서 호출되는 함수가 코드에서 함수 위에 있어야 하는 경우, 그렇지 않으면 컴파일러가 함수를 컴파일하기 전에 해당 함수를 찾지 못할 수 있다는 점을 잊지 마십시오.그러면 해당 오류가 생성됩니다.

「 」를 했을 때error: implicit declaration of function아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아, 아.는 헤더파일을 수 셸에서 "", "", "", "", "", "", "", "", "", "", "", "", "", "", """"를 입력할 수 .man 2 functionname '아예'를 .SYNOPSIS이 섹션에는 포함할 필요가 있는 헤더 파일이 나열됩니다.또는 http://linux.die.net/man/에 접속하세요.이것은 하이퍼링크 되어 검색하기 쉬운 온라인 맨 페이지입니다.함수는 대부분의 경우 헤더 파일에 정의되며, 필요한 헤더 파일이 해답이 되는 경우가 많습니다.cnicutar가 말했듯이

컴파일러가 아직 선언("프로토타입")을 인식하지 못한 함수를 사용하고 있습니다.

그 질문에 100% 답한 것은 아니라고 생각합니다.컴파일 시간 지시인 타입 오브()가 누락된 문제를 찾고 있었습니다.

다음 링크를 통해 상황을 알 수 있습니다.

https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Typeof.html

https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Alternate-Keywords.html#Alternate-Keywords

경련으로 사용하려고 하다__typeof__()대신.또한.gcc ... -Dtypeof=__typeof__ ...도움이 됩니다.

올바른 헤더가 정의되어 있고, 이 헤더를 사용하고 있지 않은 경우GlibC라이브러리(Musl C 등)gcc또한 던질 것이다error: implicit declaration of function다음과 같은 GNU 확장자malloc_trim가 검출되었습니다.

해결책은 확장과 헤더를 랩하는 것입니다.

#if defined (__GLIBC__)
  malloc_trim(0);
#endif

이 오류는 컴파일러가 인식하지 못하는 함수를 사용하려고 하기 때문에 발생합니다.사용하려는 함수가 C 언어로 미리 정의되어 있는 경우 암묵 함수와 관련된 헤더 파일만 포함합니다.미리 정의된 함수가 아닌 경우 항상 함수를 메인 함수보다 먼저 선언하는 것이 좋습니다.

언급URL : https://stackoverflow.com/questions/8440816/warning-implicit-declaration-of-function

반응형