2011-07-14 99 views
4

在以下代碼行中,dup_func,free_func和clear_free func前的星號是幹什麼的?函數名稱前的星號是什麼意思?

void *(*dup_func)(void *); 
void (*free_func)(void *); 
void (*clear_free_func)(void *); 
+2

什麼語言?我猜C,但誰知道。 – aroth

+0

這裏是第一個意思是:[cdecl](http://cdecl.ridiculousfish.com/?q=void+*%28*dup_func%29%28void+*%29%3B) –

+0

[void(* a)(char *,char *);這是一個函數?](http://stackoverflow.com/questions/5546867/void-achar-char-is-this-a-function) – outis

回答

9

在您的示例中,這意味着它們是function pointers

簡而言之,它們允許你做這樣的事情:

void example() 
{ 
    printf("Example called!\n"); 
} 

void call_my_function(void (*fun)()) 
{ 
    printf("Calling some function\n"); 
    (*fun)(); 
} 

/* Later. */ 
call_my_function(example); 
+0

請注意,空括號是舊式(K&R C),由C99廢棄。你應該在無效的地方加上'void'。 – Jens

相關問題