[英]GCC warning with std=c11 arg
Here is a little C source code using pthread_kill() call: 这是一个使用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;
}
Gcc compilation produces various results depending on -std argument value (see below). Gcc编译根据-std参数值产生各种结果(见下文)。 I don't understand these different behaviors.
我不明白这些不同的行为。 I didn't get interesting informations into man pages except pthread_kill() is POSIX.1-2008 compliant.
除了pthread_kill()符合POSIX.1-2008之外,我没有在手册页中获得有趣的信息。
Environment: Linux 3.2 64bits. 环境:Linux 3.2 64位。 GCC 4.7.2.
GCC 4.7.2。
gcc main.c -std=c11 -pthread
I get an implicit declaration: 我得到一个隐含的声明:
main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
gcc main.c -std=c99 -pthread
Same result as -std=c11: 与-std = c11相同的结果:
main.c:9:2: warning: implicit declaration of function ‘pthread_kill’ [-Wimplicit-function-declaration]
gcc main.c -std=c90 -pthread
It simply works without any errors/warnings. 它只是没有任何错误/警告。
Thank you for your feedbacks. 感谢您的反馈。
If you use a Posix feature, you need to define an appropriate feature test macro. 如果使用Posix功能,则需要定义适当的功能测试宏。 See
man feature_test_macros
or the Posix standard . 请参阅
man feature_test_macros
或Posix标准 。
If you don't define _POSIX_C_SOURCE
to an appropriate value (depending on the minimum Posix level you require), then interfaces from that and subsequent Posix standards will not be defined by standard library headers. 如果未将
_POSIX_C_SOURCE
定义为适当的值(取决于所需的最小Posix级别),那么标准库标题将不会定义来自该Posix标准和后续Posix标准的接口。
If you need Posix.1-2008, for example, you need to do this: 例如,如果您需要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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.