GCC warning with std = c11 arg

Here is the small C source code using pthread_kill ():

#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; } 

Compiling Gcc produces different results depending on the value of the -std argument (see below). I do not understand these different behaviors. I did not get any interesting information in the man pages, except that pthread_kill () is POSIX.1-2008 compatible.

Environment: Linux 3.2 64 bit. GCC 4.7.2.

C -std = c11

 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] 

C -std = c99

 gcc main.c -std=c99 -pthread 

Same result as -std = c11:

 main.c:9:2: warning: implicit declaration of function 'pthread_kill' [-Wimplicit-function-declaration] 

C -std = c90

 gcc main.c -std=c90 -pthread 

It just works without any errors / warnings.

Thanks for your feedback.

+5
source share
1 answer

If you use the Posix function, you need to define a suitable function check macro. See man feature_test_macros or the Posix standard .

If you do not define _POSIX_C_SOURCE appropriate value (depending on the minimum Posix level you need), then the interfaces from this and subsequent Posix standards will not be defined by standard library headers.

If you need Posix.1-2008, for example, you need to do this:

 #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; } 
+8
source

Source: https://habr.com/ru/post/1208949/


All Articles