这是一段使用 pthread_kill() 调用的 C 代码示例:
#include <stdlib.h>
#include <pthread.h>
#include <signal.h>
int main(int argc, char *argv[])
{
pthread_t th = NULL;
pthread_kill(th, 0);
return 0;
}
使用不同的-std参数值,gcc编译会产生不同的结果(见下文)。我不理解这些不同的行为。除了pthread_kill()是符合POSIX.1-2008标准的,我在man手册中没有找到有趣的信息。
环境:Linux 3.2 64位操作系统,GCC 4.7.2。
使用-std=c11参数
gcc main.c -std=c11 -pthread
我收到了一个隐式声明:
main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
With -std=c99
gcc main.c -std=c99 -pthread
与-std=c11相同的结果:
main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
With -std=c90
gcc main.c -std=c90 -pthread
它能够在没有任何错误/警告的情况下简单地运行。
感谢您的反馈。
-lpthread
而不是-pthread
? - Sourav Ghosh-std=gnu99
或例如-std=gnu11
标志,它们为您提供了对相应 C 标准的扩展,其中包括库特性,如在 Linux 上使用 glibc 时的 posix 函数。 - nos