2017-09-10 5 views
2
typedef struct foo{ 
    void (*del)(void *toDel); 
    char* (*p)(void *tp) 
} Foo; 

Foo init(char* (*print)(void*),void (*delFunc)(void*)); 

제공된 매개 변수를 struct 함수 포인터에 할당하거나 초기화하는 방법을 알아 내려고합니다. 이것에 대해구조체 함수 포인터 초기화

Return (Foo){.del=delFunc, .p=print}; 

답변

3
Foo init(char* (*print)(void *toBePrinted),void (*delFunc)(void *toBeDeleted)) 
{ 
    return Foo{ .del = delFunc, .p = print}; 
} 

무엇을 :

+0

당신은 .del = delFunc .p = print입니까? – waffles

+0

@waffles 예, 정확히 말하면 미안합니다 –

+0

는 C99 또는 C11 표준 표기법입니까? – iBug

0

직진 (대부분의 이전 버전과 호환 접근 방식) Foofoo를 정의하고이 초기화하기 :

Foo foo = { /* Mind the order of the following initialisers! */ 
    delFunc, 
    print 
};