【发布时间】:2015-07-28 06:58:56
【问题描述】:
我有一个头文件定义了一些代码如下所示:
typedef uint8_t EnrollT(uint16_t test1, uint16_t test2);
typedef void ChangeT(uint64_t post1, uint8_t post2);
struct ClusterT * ClientAlloc(EnrollT *, ChangeT *);
我有以下问题:
-
下面的代码是否相等?
typedef uint8_t EnrollT(uint16_t test1, uint16_t test2); typedef uint8_t (*EnrollT)(uint16_t test1, uint16_t test2); 在包含此标头的 C 文件中,如何在 ClientAlloc 函数中处理这两个参数?示例代码对我来说很棒。
================================================ ==========================
感谢您的回复。 通过拥有两个真正的函数,我将它们传递给以下代码:
ClientAlloc(Enroll, Change)
但是,当我编译代码时,出现以下错误,这里有什么遗漏吗?
expected declaration specifiers or ‘...’ before ‘Enroll’
expected declaration specifiers or ‘...’ before ‘NotifyChange’
【问题讨论】:
-
@SouravGhosh,您介意再解释一下吗?
-
在第一个语句中,您正在为
uint8_t创建一个别名,在第二个语句中,您正在创建一个函数指针。 -
为了您的更新,我们需要查看那些函数定义——或者,至少,函数定义的签名部分。您的代码提到“更改”,错误消息提到“通知更改”;这使我们认为在您写信给 SO 之前正在进行一些编辑。如果您要这样做,请确保我们无法发现您正在这样做!
-
@JonathanLeffler 我不完全确定这是那个问题的重复......它的第二部分似乎可能会问更多......但没关系。
-
@Freenode-newbostonSebivor:有很多可能的替代副本:Understanding typedefs for function pointers; Typedeffing a function (NOT a function pointer); How do function pointers in C work;我敢肯定还有其他可能性。
标签: c function-pointers typedef