【发布时间】:2012-03-14 02:38:24
【问题描述】:
我一直在查看 glibc 的一些源代码,尤其是 nptl 代码,我发现它有点难以理解,因为它似乎有我不熟悉的约定。
例如,我正在查看一个非常小的文件 pthread_equal.c,我有一些问题:
22 int
23 __pthread_equal (thread1, thread2)
24 pthread_t thread1;
25 pthread_t thread2;
26 {
27 return thread1 == thread2;
28 }
29 strong_alias (__pthread_equal, pthread_equal)
第 22 行和第 23 行的声明看起来像我理解的那样。它的返回类型为
int,然后是函数名__pthread_equal和参数列表(thread1, thread2)。但是第 24 行pthread_t thread1;和 25pthread_t thread2;上的声明是什么?看起来这些被声明为全局变量,但我不明白目的。我在 nptl 目录中的许多文件中都看到了这种模式,但无法弄清楚为什么会这样。什么是
strong_alias?一个快速的谷歌搜索有这个使用的例子,但我没有找到任何文档的链接。-
有些名字前面加两个下划线
__,有些名字前面加一个下划线_是什么原因。我见过的大部分代码都使用两个下划线,但我想我见过一些使用一个下划线的地方。比如pthreadP.h556 /* Old cleanup interfaces, still used in libc.so. */ 557 extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer, 558 void (*routine) (void *), void *arg); 559 extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer, 560 int execute); 561 extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer, 562 void (*routine) (void *), void *arg); 563 extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer, 564 int execute);
诚然,代码前面有一条注释,上面写着“旧的清理接口”,但无论哪种方式,我都很好奇其中的区别以及为什么有时使用一个下划线,有时使用两个下划线。
感谢您提供有关这些问题的任何信息。
【问题讨论】: