typedef struct foo{
void (*del)(void *toDel);
char* (*p)(void *tp)
} Foo;
Foo init(char* (*print)(void*),void (*delFunc)(void*));
試圖找出如何分配或初始化提供給struct函數指針的參數。初始化結構中的函數指針
typedef struct foo{
void (*del)(void *toDel);
char* (*p)(void *tp)
} Foo;
Foo init(char* (*print)(void*),void (*delFunc)(void*));
試圖找出如何分配或初始化提供給struct函數指針的參數。初始化結構中的函數指針
Foo init(char* (*print)(void *toBePrinted),void (*delFunc)(void *toBeDeleted))
{
return Foo{ .del = delFunc, .p = print};
}
這個是什麼?龍形態:
Foo init(char* (*print)(void *toBePrinted),void (*delFunc)(void *toBeDeleted))
{
Foo tmp = {
.del = delFunc,
.p = print
};
return tmp;
}
How to initialize a struct in accordance with C programming language standards
你可以做到這一點的常用方法:
Return (Foo){.del=delFunc, .p=print};
的直線前進(最向後兼容的方法)來定義foo
爲Foo
並初始化它:
Foo foo = { /* Mind the order of the following initialisers! */
delFunc,
print
};
did you mean .del = delFunc .p = print? – waffles
@waffles是的,確切地說,對不起 –
是C99還是C11標準符號? – iBug