2011-11-15 52 views
6

在linux下,container_of宏被封閉在看似 「多餘」 的括號:爲什麼我們需要圍繞宏塊的括號?

#define container_of(ptr, type, member) ({ \ 
       const typeof(((type *)0)->member) *__mptr = (ptr); 
       (type *)((char *)__mptr - offsetof(type,member));}) 

取而代之的是,我們可以只使用

#define container_of(ptr, type, member) { \ 
       const typeof(((type *)0)->member) *__mptr = (ptr); 
       (type *)((char *)__mptr - offsetof(type,member));} 

圓括號是強制性還是僅用於預防?

+0

這應被標記GCC而不是C ....... –

回答

相關問題