typestar

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

  1. The macro must be defined before any header is included.
  2. 200809L selects POSIX.1-2008, which covers most of what you want.
  3. Without it, a POSIX call may compile as an implicit declaration.

Keywords and builtins used here

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.

Type this snippet

Step 4 of 4 in Program environment, step 4 of 14 in Systems programming.

← Previous Next →