너와 함께 마침내 함수 포인터로 코드를 컴파일했다. 하지만 지금은 똑같은 일을하고 싶지만 "외부"라이브러리의 기능을 원합니다. typedef, arguments, compilation 플래그는 100 % 괜찮습니다. 외부 라이브러리에서 함수를 호출하려고 할 때만이 경고가 나타납니다 (동일한 프로토 타입으로 함수를 작성하고이 코드로 호출하려고했을 때 괜찮 았습니다) . 어떤 아이디어?함수 포인터 - 외부 라이브러리, 경고 : 호환되지 않는 포인터 유형에서 초기화
#include <stdio.h>
#include <stdlib.h>
#include "libs/outlib.h"
typedef int (*VFUNCV)(int, double);
void call(int which, VFUNCV* fun, int a, double b)
{
fun[which](a, b);
}
int main()
{
VFUNCV fun[2] = {outlibfun1, outlibfun2};
call(0, fun, 3, 4.5);
return 0;
}
경고 :
funargs.c: In function ‘main’:
funargs.c:14:5: warning: initialization from incompatible pointer type [enabled by default]
funargs.c:14:5: warning: (near initialization for ‘fun[0]’) [enabled by default]
funargs.c:14:5: warning: initialization from incompatible pointer type [enabled by default]
funargs.c:14:5: warning: (near initialization for ‘fun[1]’) [enabled by default]
그리고 14 라인 :
VFUNCV fun[2] = {outlibfun1, outlibfun2};
선언 outlibfun
의 : int outlibfun1(int, double);
ANOTHER하지-WORKING (경고) 예 :
01 함수가 동일한 소스와 함수 포인터를 할당하기 전에 선언되지 않은 경우 23,516,#include <stdio.h>
#include <stdlib.h>
#include "libs/outlibz2.h"
typedef unsigned char* (*VFUNCV)(const unsigned char *, unsigned long, unsigned char *);
void call(int which, VFUNCV* fun, const unsigned char *a, unsigned long b, unsigned char * c)
{
fun[which](a, b, c);
}
int main()
{
VFUNCV fun[2] = {outlibfun1};
call(0, fun, "b", 3, "a");
return 0;
}
'outlibfun1'과 'outlibfun2'의 서명은 무엇입니까? –