鍍金池/ 問答/C  Linux/ pthread源碼中__nonnull和__THROW的作用是什么?

pthread源碼中__nonnull和__THROW的作用是什么?

在pthread.h頭文件中:

extern int pthread_once (pthread_once_t *__once_control,                                       
               void (*__init_routine) (void)) __nonnull ((1, 2));
    
extern int pthread_atfork (void (*__prepare) (void),                                                                                                                                           
               void (*__parent) (void),                                                                                                                                                        
               void (*__child) (void)) __THROW

我想請(qǐng)教的是__nonnull__THROW的定義/實(shí)現(xiàn)在哪里?(我翻遍了頭文件都沒找到...), 它們的作用是什么?
先提前表示感謝!

回答
編輯回答
舊酒館

__THROW的定義在 include/sys/cdefs.h

54    # if !defined __cplusplus && __GNUC_PREREQ (3, 3)
55    #  define __THROW    __attribute__ ((__nothrow__ __LEAF))
56    #  define __THROWNL    __attribute__ ((__nothrow__))
57    #  define __NTH(fct)    __attribute__ ((__nothrow__ __LEAF)) fct
58    #  define __NTHNL(fct)  __attribute__ ((__nothrow__)) fct
59    # else
60    #  if defined __cplusplus && __GNUC_PREREQ (2,8)
61    #   define __THROW    throw ()
62    #   define __THROWNL    throw ()
63    #   define __NTH(fct)    __LEAF_ATTR fct throw ()
64    #   define __NTHNL(fct) fct throw ()
65    #  else
66    #   define __THROW
67    #   define __THROWNL
68    #   define __NTH(fct)    fct
69    #   define __NTHNL(fct) fct
70    #  endif
71    # endif

__nonnull

286    /* The nonull function attribute allows to mark pointer parameters which
287       must not be NULL.  */
288    #if __GNUC_PREREQ (3,3)
289    # define __nonnull(params) __attribute__ ((__nonnull__ params))
290    #else
291    # define __nonnull(params)
292    #endif

參見
https://code.woboq.org/qt5/in...

2017年5月13日 19:30