开发者

macro: does #define a(b) ({... c;}) means a(b) returns c?

开发者 https://www.devze.com 2023-04-09 18:10 出处:网络
I have this code in linux kernel: #define task_cred_xxx(task, xxx) ({ __typeof_开发者_开发百科_(((struct cred *)NULL)->xxx) ___val;

I have this code in linux kernel:

#define task_cred_xxx(task, xxx)                        
({                                                      
    __typeof_开发者_开发百科_(((struct cred *)NULL)->xxx) ___val;  
    rcu_read_lock();                               
    ___val = __task_cred((task))->xxx;              
    rcu_read_unlock();                              
    ___val;                                         
})

I never saw macro defined like this before, does that mean this is task_cred_xxx(task, xxx) returns ___val?

Thanks!


Correct. It will return ___val. However, block expressions like these are a GNU extension and isn't actually part of the C standard.

http://www.toofishes.net/blog/gcc-compound-statement-expressions/

0

精彩评论

暂无评论...
验证码 换一张
取 消