1. 程式人生 > >c語言/VOID(*)

c語言/VOID(*)

首先,(void (*)( )) 是一個型別名(type name),而且指定的是一個指標型別,又不是函式型別。
其次,那一對空的括號並不意味著引數為空。N1570,6.7.6.3  Function declarators (including prototypes):
The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied.

這就是說,如果在函式宣告中使用空的引數列表,則意味著未提供引數的數量或型別資訊,但並不是無引數。從C99開始,如果函式沒有引數,建議使用(void)。
C/C++ code ?
1 2 3 4 5 6 7 8 9 10 int main (void) { void f(); f(2); } void f (int i) { printf("%d\n", i); }

參考 http://bbs.csdn.net/topics/390769303