Flo*_*low 5 c gcc pthreads c11
这是一个使用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;
}
Run Code Online (Sandbox Code Playgroud)
Gcc编译根据-std参数值产生各种结果(见下文).我不明白这些不同的行为.除了pthread_kill()符合POSIX.1-2008之外,我没有在手册页中获得有趣的信息.
环境:Linux 3.2 64位.GCC 4.7.2.
gcc main.c -std=c11 -pthread
Run Code Online (Sandbox Code Playgroud)
我得到一个隐含的声明:
main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
Run Code Online (Sandbox Code Playgroud)
gcc main.c -std=c99 -pthread
Run Code Online (Sandbox Code Playgroud)
与-std = c11相同的结果:
main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
Run Code Online (Sandbox Code Playgroud)
gcc main.c -std=c90 -pthread
Run Code Online (Sandbox Code Playgroud)
它只是没有任何错误/警告.
感谢您的反馈.
如果使用Posix功能,则需要定义适当的功能测试宏.请参阅man feature_test_macros或Posix标准.
如果你没有定义_POSIX_C_SOURCE一个适当的值(取决于您所需要的最低水平Posix的),然后从该接口和随后的Posix标准将不受标准库头文件中定义.
例如,如果您需要Posix.1-2008,则需要执行以下操作:
#define _POSIX_C_SOURCE 200809L
#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;
}
Run Code Online (Sandbox Code Playgroud)