Feature test macros in C
Strict ISO mode hides POSIX declarations until you ask for them by name.
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <unistd.h>
void which_standard(void) {
#if defined(_POSIX_VERSION)
printf("POSIX %ld\n", (long) _POSIX_VERSION);
#else
printf("no POSIX headers\n");
#endif
printf("C standard %ld\n", (long) __STDC_VERSION__);
printf("pid %d\n", (int) getpid());
}
How it works
- The macro must be defined before any header is included.
200809Lselects POSIX.1-2008, which covers most of what you want.- Without it, a POSIX call may compile as an implicit declaration.
Keywords and builtins used here
intlongvoidwhich_standard
The run, in numbers
- Lines
- 14
- Characters to type
- 308
- Tokens
- 70
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 44 seconds.
Step 4 of 4 in Program environment, step 4 of 14 in Systems programming.