2015-07-28 96 views
1

我的頭定義了以下代碼:Ç - 前函數參數預期的聲明符或「...」

typedef uint8_t EnrollT(uint16_t test1, uint16_t test2); 
typedef void ChangeT(uint64_t post1, uint8_t post2); 

struct ClusterT * ClientAlloc(EnrollT *, ChangeT *); 

我已經實現了這兩個功能,並在我的C文件傳遞那些ClientAlloc()作爲如下所示:

ClientAlloc(Enroll, Change); 

但是,當我編譯源時,彈出錯誤。

expected declaration specifiers or ‘...’ before ‘enroll’ 
expected declaration specifiers or ‘...’ before ‘change’ 

有什麼我可能會在這裏錯過嗎?

對於EnrollTChangeT,我宣佈它在我的代碼:

uint8_t Enroll(uint16_t test1, uint16_t test2){...}; 
void Change(uint64_t post1, uint8_t post2){...}; 

對於ClienAlloc

struct ClusterT * ClientAlloc(Enroll, Change){... return something}; 
+0

你怎麼申報'enroll'和'change'? –

+1

刪除了我的答案,因爲雖然*可能*在某處忘記了分號,但沒有人能真正告訴這一小段代碼。請顯示一個完整的可證實的問題示例。 –

+0

@MichaelWalz和Felix,我已經更新了我的問題。 – user3815726

回答

1

要傳遞到你的EnrollChange功能ClientAlloc函數地址

然後你的

struct ClusterT * ClientAlloc(Enroll, Change){... return something} 

必須

struct ClusterT *ClientAlloc(EnrollT *p, ChangeT *q){... return something} 

一個例子代碼:

#include <stdint.h> 
#include <stdlib.h> 

typedef uint8_t EnrollT(uint16_t test1, uint16_t test2); 
typedef void ChangeT(uint64_t post1, uint8_t post2); 

struct ClusterT *ClientAlloc(EnrollT *p, ChangeT *q) 
{ 
    return NULL; 
} 

uint8_t enroll(uint16_t test1, uint16_t test2) 
{ 
    return 0; 
} 

void change(uint64_t post1, uint8_t post2) 
{ 

} 

int main(void) { 

    ClientAlloc(enroll, change); 

    return 0; 
} 
+0

刪除了我的評論,謝謝你的示例代碼。 – user3815726

+0

在我的情況下,ClientAlloc將是要執行的函數。我在這裏沒有主要。你能修改示例代碼嗎? – user3815726

+0

@ user3815726由什麼執行?不是功能?將代碼'ClientAlloc(登記,更改)'移到你需要的地方。 – LPs

1

這這裏編譯罰款:

typedef uint8_t EnrollT(uint16_t test1, uint16_t test2); 
typedef void ChangeT(uint64_t post1, uint8_t post2); 

struct ClusterT * ClientAlloc(EnrollT *, ChangeT *); 


struct ClusterT * ClientAlloc(EnrollT *x, ChangeT *y) 
{ 
    (*x)(22,33); 
    return NULL; 
} 


unsigned char enrollfunc(uint16_t test1, uint16_t test2) 
{ 
    return 123; 
} 

void main() 
{ 
    EnrollT *x = enrollfunc; 
    ChangeT *y = NULL; 


    ClientAlloc(x, y); 
} 
+0

在我的情況下,ClientAlloc將是要執行的功能。我在這裏沒有主要。你能修改示例代碼嗎? – user3815726

+0

@ user3815726爲什麼修改編譯的代碼並且工作正常?我不確定我明白。 –

+0

你是對的,對不起,我誤解了代碼。 – user3815726