1FEATURE_TEST_MACROS(7) Linux Programmer's Manual FEATURE_TEST_MACROS(7)
2
3
4
6 feature_test_macros - feature test macros
7
9 Feature test macros allow the programmer to control the definitions
10 that are exposed by system header files when a program is compiled.
11
12 NOTE: In order to be effective, a feature test macro must be defined
13 before including any header files. This can be done either in the com‐
14 pilation command (cc -DMACRO=value) or by defining the macro within the
15 source code before including any headers.
16
17 Some feature test macros are useful for creating portable applications,
18 by preventing nonstandard definitions from being exposed. Other macros
19 can be used to expose nonstandard definitions that are not exposed by
20 default.
21
22 The precise effects of each of the feature test macros described below
23 can be ascertained by inspecting the <features.h> header file. Note:
24 applications do not need to directly include <features.h>; indeed,
25 doing so is actively discouraged. See NOTES.
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 understoo