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