2012-02-16 214 views
1

的語法netif_napi_add時是:「時將整數指針,未作鑄造」呼叫netif_napi_add

netif_napi_add(struct net_device *dev, struct napi_struct *napi,int (*poll)(struct napi_struct *, int), int weight) 

它用於初始化NAPI結構。問題是,當我使用功能:

netif_napi_add(wdev,rnapi,rrpoll(rnapi,20),16); 

它給了我一個編譯警告:

warning: passing argument 3 of ‘netif_napi_add’ makes pointer from integer without a cast 
/usr/src/linux-2.6.34.10-0.6/include/linux/netdevice.h:1089:6: note: expected ‘int (*)(struct napi_struct *, int)’ but argument is of type ‘int’ 

如何解決呢?

回答

4

的第三個參數netif_napi_addint (*poll)(struct napi_struct *, int),是一個function pointer名爲poll指向,需要一個struct napi_struct *int並返回int的功能。您直接調用rrpoll並將其返回值(int)傳遞給netif_napi_add,而不是函數指針。你可能只想通過rrpoll直接功能:

netif_napi_add(wdev, rnapi, &rrpoll, 16); 
+0

注意,'&'是可選的,因爲一個函數的名稱通常是「衰變」的指針功能:'netif_napi_add(wdev,RNAPI ,rrpoll,16);' – 2012-02-16 09:41:05

+0

@KeithThompson這是困擾我的「通常」;它永遠不會錯,所以我總是包含它 – 2012-02-16 14:48:05

+0

唯一的例外是當函數名是sizeof或者_Alignof(C11中的new)的操作數(兩者都是非法的),以及它是一元操作數時'&'。省略'&'是安全的。 (但正如你所說,包含它也是保存。) – 2012-02-16 17:11:06

2

第三個參數應該是一個函數指針,而不是返回值,你應該把它像:

netif_napi_add(wdev,rnapi,&rrpoll,16); 

(除非rrpoll返回一個指向給定類型的功能,但我不要以爲這樣的話:)