1FEATURE_TEST_MACROS(7) Linux Programmer's Manual FEATURE_TEST_MACROS(7)
2
3
4
6 feature_test_macros - feature test macros
7
9 #include <features.h>
10
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 non-standard definitions from being exposed. Other macros can be used
16 to expose non-standard definitions that are not exposed by default.
17 The precise effects of each of the feature test macros described below
18 can 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 Linux/glibc understands the following feature test macros:
26
27 _POSIX_C_SOURCE
28 Defining this macro with the value 1 causes header files to
29 expose definitions conforming to POSIX.1-1990 and ISO C (1990).
30 Defining with the value 199309 or greater additionally exposes
31 definitions for POSIX.1b (real-time extensions). Defining with
32 the value 199506 or greater additionally exposes definitions for
33 POSIX.1c (threads). Defining with the value 200112 exposes def‐
34 initions corresponding to the POSIX.1-2001 base specification
35 (excluding the XSI extension).
36
37 _POSIX_SOURCE
38 Defining this obsolete macro with any value is equivalent to
39 defining _POSIX_C_SOURCE with the value 1.
40
41 _XOPEN_SOURCE
42 Defining this macro with any value causes header files to expose
43 definitions conforming to POSIX.1, POSIX.2, and XPG4. Defining
44 with the value 500 or greater additionally exposes definitions
45 for SUSv2 (UNIX 98). Defining with the value 600 or greater
46 additionally exposes definitions for SUSv3 (UNIX 03; i.e., the
47 POSIX.1-2001 base specification plus the XSI extension) and C 99
48 definitions.
49
50 _XOPEN_SOURCE_EXTENDED
51 If this macro is defined with the value 1, and the _XOPEN_SOURCE
52 is defined, then expose definitions corresponding to the XPG4v2
53 UNIX extensions.
54
55 _ISOC99_SOURCE
56 Exposes C 99 extensions to ISO C (1990).
57
58 _LARGEFILE64_SOURCE
59 Expose definitions for the alternative API specified by the LFS
60 (Large File Summit) as a "transitional extension" to the Single
61 UNIX Specification. (See http://opengroup.org/plat‐
62 form/lfs.html.)
63
64 _FILE_OFFSET_BITS
65 Defining this macro with the value 64 automatically converts
66 references to 32-bit functions and data types related to file
67 I/O and file system operations into references to their 64-bit
68 counterparts. This is useful for performing I/O on large files
69 (> 2 Gigabytes) on 32-bit systems.
70
71 _BSD_SOURCE
72 Defining this macro with any value cause header files to expose
73 BSD-derived definitions. Defining this macro also causes BSD
74 definitions to be preferred in some situations where standards
75 conflict.
76
77 _SVID_SOURCE
78 Defining this macro with any value cause header files to expose
79 System V-derived definitions. (SVID == System V Interface Defi‐
80 nition; see standards(7).)
81
82 _GNU_SOURCE
83 Defining this macro (with any value) is equivalent to defining
84 _BSD_SOURCE, _SVID_SOURCE, _LARGEFILE64_SOURCE, _ISOC99_SOURCE
85 _POSIX_C_SOURCE with the value 1999506, and _XOPEN_SOURCE with
86 the value 600. In addition, various GNU-specific extensions are
87 also exposed.
88
89 _REENTRANT
90 Defining this macro exposes definitions of certain reentrant
91 functions. For multithreaded programs, use cc -pthread instead.
92
93 _THREAD_SAFE
94 Synonym for _REENTRANT, provided for compatibility with some
95 other implementations.
96
97 _FORTIFY_SOURCE
98 Defining this macro causes some lightweight checks to be per‐
99 formed to detect some buffer overflow errors when employing var‐
100 ious string and memory manipulation functions. Not all buffer
101 overflows are detected, just some common cases. In the current
102 implementation checks are added for calls to memcpy(3), mem‐
103 pcpy(3), memmove(3), memset(3), stpcpy(3), strcpy(3),
104 strncpy(3), strcat(3), strncat(3), sprintf(3), snprintf(3),
105 vsprintf(3), vsnprintf(3), and gets(3). If _FORTIFY_SOURCE is
106 set to 1, with compiler optimization level 1 (gcc -O1) and
107 above, checks that shouldn't change the behaviour of conforming
108 programs are performed. With _FORTIFY_SOURCE set to 2 some more
109 checking is added, but some conforming programs might fail.
110 Some of the checks can be performed at compile time, and result
111 in compiler warnings; other checks take place at run time, and
112 result in a run-time error if the check fails. Use of this
113 macro requires compiler support, available with gcc(1) since
114 version 4.0.
115
116 When gcc(1) is invoked, the following macros are defined by default:
117 _BSD_SOURCE, _SVID_SOURCE, _POSIX_SOURCE, and _POSIX_C_SOURCE=199506.
118 If individual macros are defined, then other macros are disabled unless
119 they are also explicitly defined. (Exception: if _POSIX_C_SOURCE is
120 not otherwise defined, then it is always defined with the value 200112
121 (199506 in glibc versions before 2.4), unless the compiler is invoked
122 in one of its standard modes, e.g., the -std=c99 flag.) Multiple
123 macros can be defined; the results are additive.
124
126 POSIX.1 specifies _POSIX_C_SOURCE, _POSIX_SOURCE, and _XOPEN_SOURCE.
127 _XOPEN_SOURCE_EXTENDED was specified by XPG4v2 (aka SUSv1). _FILE_OFF‐
128 SET_BITS is not specified by any standard, but is employed on some
129 other implementations. _BSD_SOURCE, _SVID_SOURCE, _GNU_SOURCE, _FOR‐
130 TIFY_SOURCE, _REENTRANT, and _THREAD_SAFE are Linux (glibc) specific.
131
133 <features.h> is a Linux/glibc specific header file. Other systems have
134 an analogous file, but typically with a different name. This header
135 file is automatically included by other header files as required: it is
136 not necessary to explicitly include it in order to employ feature test
137 macros.
138
139 According to which of the above feature test macros are defined, <fea‐
140 tures.h> internally defines various other macros that are checked by
141 other glibc header files. These macros have names prefixed by two
142 underscores (e.g., __USE_MISC). Programs should never define these
143 macros directly: instead, the appropriate feature test macro(s) from
144 the list above should be employed.
145
146
147
148Linux 2006-04-26 FEATURE_TEST_MACROS(7)