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

我想请教的是__nonnull__THROW的定义/实现在哪里?(我翻遍了头文件都没找到...), 它们的作用是什么?
先提前表示感谢!

阅读 5.1k
1 个回答

__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...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进