1FEATURE_TEST_MACROS(7)     Linux Programmer's Manual    FEATURE_TEST_MACROS(7)
2
3
4

NAME

6       feature_test_macros - feature test macros
7

SYNOPSIS

9       #include <features.h>
10

DESCRIPTION

12       Feature  test  macros  allow  the programmer to control the definitions
13       that are exposed by system header files when a program is compiled.
14
15       NOTE: In order to be effective, a feature test macro  must  be  defined
16       before including any header files.  This can be done either in the com‐
17       pilation command (cc -DMACRO=value) or by defining the macro within the
18       source code before including any headers.
19
20       Some feature test macros are useful for creating portable applications,
21       by preventing nonstandard definitions from being exposed.  Other macros
22       can  be  used to expose nonstandard definitions that are not exposed by
23       default.  The precise effects  of  each  of  the  feature  test  macros
24       described  below  can  be  ascertained  by  inspecting the <features.h>
25       header file.
26
27   Specification of feature test macro requirements in manual pages
28       When a function requires that a feature test macro is defined, the man‐
29       ual page SYNOPSIS typically includes a note of the following form (this
30       example from the acct(2) manual page):
31
32               #include <unistd.h>
33
34               int acct(const char *filename);
35
36           Feature Test Macro Requirements for glibc (see
37           feature_test_macros(7)):
38
39               acct(): _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
40
41       The || means that in order to obtain the declaration  of  acct(2)  from
42       <unistd.h>,  either  of  the  following  macro definitions must be made
43       before including any header files:
44
45              #define _BSD_SOURCE
46              #define _XOPEN_SOURCE        /* or any value < 500 */
47
48       Alternatively, equivalent definitions can be included in  the  compila‐
49       tion command:
50
51              cc -D_BSD_SOURCE
52              cc -D_XOPEN_SOURCE           # Or any value < 500
53
54       Note  that, as described below, some feature test macros are defined by
55       default, so that it may not always be necessary to  explicitly  specify
56       the feature test macro(s) shown in the SYNOPSIS.
57
58       In a few cases, manual pages use a shorthand for expressing the feature
59       test macro requirements (this example from readahead(2)):
60
61              #define _GNU_SOURCE
62              #include <fcntl.h>
63
64              ssize_t readahead(int fd, off64_t *offset, size_t count);
65
66       This format is employed in cases where only a single feature test macro
67       can  be  used to expose the function declaration, and that macro is not
68       defined by default.
69
70   Feature test macros understood by glibc
71       The following paragraphs explain how feature test macros are handled in
72       Linux glibc 2.x, x > 0.