]> git.ipfire.org Git - thirdparty/glibc.git/blame - manual/creature.texi
powerpc: Fix build of wcscpy with --disable-multi-arch
[thirdparty/glibc.git] / manual / creature.texi
CommitLineData
28f540f4
RM
1@node Feature Test Macros
2@subsection Feature Test Macros
3
4@cindex feature test macros
5The exact set of features available when you compile a source file
6is controlled by which @dfn{feature test macros} you define.
7
8If you compile your programs using @samp{gcc -ansi}, you get only the
f65fd747 9@w{ISO C} library features, unless you explicitly request additional
28f540f4 10features by defining one or more of the feature macros.
1f6676d7 11@xref{Invoking GCC,, GNU CC Command Options, gcc, The GNU CC Manual},
28f540f4
RM
12for more information about GCC options.@refill
13
14You should define these macros by using @samp{#define} preprocessor
15directives at the top of your source code files. These directives
16@emph{must} come before any @code{#include} of a system header file. It
17is best to make them the very first thing in the file, preceded only by
18comments. You could also use the @samp{-D} option to GCC, but it's
19better if you make the source files indicate their own meaning in a
20self-contained way.
21
6796bc80
UD
22This system exists to allow the library to conform to multiple standards.
23Although the different standards are often described as supersets of each
24other, they are usually incompatible because larger standards require
25functions with names that smaller ones reserve to the user program. This
26is not mere pedantry --- it has been a problem in practice. For instance,
27some non-GNU programs define functions named @code{getline} that have
28nothing to do with this library's @code{getline}. They would not be
49c091e5 29compilable if all features were enabled indiscriminately.
6796bc80
UD
30
31This should not be used to verify that a program conforms to a limited
49c091e5 32standard. It is insufficient for this purpose, as it will not protect you
6796bc80 33from including header files outside the standard, or relying on semantics
b4cbd371 34undefined within the standard.
6796bc80 35
28f540f4 36@defvr Macro _POSIX_SOURCE
d08a7e4c 37@standards{POSIX.1, (none)}
28f540f4
RM
38If you define this macro, then the functionality from the POSIX.1
39standard (IEEE Standard 1003.1) is available, as well as all of the
f65fd747 40@w{ISO C} facilities.
1618c590
UD
41
42The state of @code{_POSIX_SOURCE} is irrelevant if you define the
43macro @code{_POSIX_C_SOURCE} to a positive integer.
28f540f4
RM
44@end defvr
45
86187531 46@defvr Macro _POSIX_C_SOURCE
d08a7e4c 47@standards{POSIX.2, (none)}
1618c590
UD
48Define this macro to a positive integer to control which POSIX
49functionality is made available. The greater the value of this macro,
50the more functionality is made available.
51
52If you define this macro to a value greater than or equal to @code{1},
53then the functionality from the 1990 edition of the POSIX.1 standard
54(IEEE Standard 1003.1-1990) is made available.
55
56If you define this macro to a value greater than or equal to @code{2},
57then the functionality from the 1992 edition of the POSIX.2 standard
58(IEEE Standard 1003.2-1992) is made available.
59
60If you define this macro to a value greater than or equal to @code{199309L},
61then the functionality from the 1993 edition of the POSIX.1b standard
62(IEEE Standard 1003.1b-1993) is made available.
63
6a3962c4
RJ
64If you define this macro to a value greater than or equal to
65@code{199506L}, then the functionality from the 1995 edition of the
66POSIX.1c standard (IEEE Standard 1003.1c-1995) is made available.
67
68If you define this macro to a value greater than or equal to
69@code{200112L}, then the functionality from the 2001 edition of the
70POSIX standard (IEEE Standard 1003.1-2001) is made available.
71
72If you define this macro to a value greater than or equal to
73@code{200809L}, then the functionality from the 2008 edition of the
74POSIX standard (IEEE Standard 1003.1-2008) is made available.
75
1618c590
UD
76Greater values for @code{_POSIX_C_SOURCE} will enable future extensions.
77The POSIX standards process will define these values as necessary, and
1f77f049 78@theglibc{} should support them some time after they become standardized.
1618c590
UD
79The 1996 edition of POSIX.1 (ISO/IEC 9945-1: 1996) states that
80if you define @code{_POSIX_C_SOURCE} to a value greater than
81or equal to @code{199506L}, then the functionality from the 1996
6a3962c4
RJ
82edition is made available. In general, in @theglibc{}, bugfixes to
83the standards are included when specifying the base version; e.g.,
84POSIX.1-2004 will always be included with a value of @code{200112L}.
28f540f4
RM
85@end defvr
86
2c6fe0bd 87@defvr Macro _XOPEN_SOURCE
ca34d7a7 88@defvrx Macro _XOPEN_SOURCE_EXTENDED
d08a7e4c 89@standards{X/Open, (none)}
6d52618b
UD
90If you define this macro, functionality described in the X/Open
91Portability Guide is included. This is a superset of the POSIX.1 and
2c6fe0bd 92POSIX.2 functionality and in fact @code{_POSIX_SOURCE} and
6d52618b 93@code{_POSIX_C_SOURCE} are automatically defined.
2c6fe0bd 94
6d52618b
UD
95As the unification of all Unices, functionality only available in
96BSD and SVID is also included.
2c6fe0bd
UD
97
98If the macro @code{_XOPEN_SOURCE_EXTENDED} is also defined, even more
99functionality is available. The extra functions will make all functions
100available which are necessary for the X/Open Unix brand.
a5a0310d
UD
101
102If the macro @code{_XOPEN_SOURCE} has the value @math{500} this includes
103all functionality described so far plus some new definitions from the
6a3962c4
RJ
104Single Unix Specification, @w{version 2}. The value @math{600}
105(corresponding to the sixth revision) includes definitions from SUSv3,
106and using @math{700} (the seventh revision) includes definitions from
107SUSv4.
28f540f4
RM
108@end defvr
109
dfd2257a 110@defvr Macro _LARGEFILE_SOURCE
d08a7e4c 111@standards{X/Open, (NONE)}
dfd2257a 112If this macro is defined some extra functions are available which
cf6960d7 113rectify a few shortcomings in all previous standards. Specifically,
dfd2257a
UD
114the functions @code{fseeko} and @code{ftello} are available. Without
115these functions the difference between the @w{ISO C} interface
116(@code{fseek}, @code{ftell}) and the low-level POSIX interface
117(@code{lseek}) would lead to problems.
118
119This macro was introduced as part of the Large File Support extension (LFS).
120@end defvr
121
310b3460 122@defvr Macro _LARGEFILE64_SOURCE
d08a7e4c 123@standards{X/Open, (NONE)}
0aa9fad6 124If you define this macro an additional set of functions is made available
e8b1163e 125which enables @w{32 bit} systems to use files of sizes beyond
dfd2257a
UD
126the usual limit of 2GB. This interface is not available if the system
127does not support files that large. On systems where the natural file
128size limit is greater than 2GB (i.e., on @w{64 bit} systems) the new
129functions are identical to the replaced functions.
130
131The new functionality is made available by a new set of types and
e8b1163e 132functions which replace the existing ones. The names of these new objects
dfd2257a
UD
133contain @code{64} to indicate the intention, e.g., @code{off_t}
134vs. @code{off64_t} and @code{fseeko} vs. @code{fseeko64}.
135
136This macro was introduced as part of the Large File Support extension
cf6960d7
UD
137(LFS). It is a transition interface for the period when @w{64 bit}
138offsets are not generally used (see @code{_FILE_OFFSET_BITS}).
310b3460 139@end defvr
dfd2257a 140
8619129f 141@defvr Macro _FILE_OFFSET_BITS
d08a7e4c 142@standards{X/Open, (NONE)}
e8b1163e 143This macro determines which file system interface shall be used, one
cf6960d7
UD
144replacing the other. Whereas @code{_LARGEFILE64_SOURCE} makes the @w{64
145bit} interface available as an additional interface,
e8b1163e 146@code{_FILE_OFFSET_BITS} allows the @w{64 bit} interface to
dfd2257a
UD
147replace the old interface.
148
e8b1163e
AJ
149If @code{_FILE_OFFSET_BITS} is undefined, or if it is defined to the
150value @code{32}, nothing changes. The @w{32 bit} interface is used and
dfd2257a
UD
151types like @code{off_t} have a size of @w{32 bits} on @w{32 bit}
152systems.
153
e8b1163e 154If the macro is defined to the value @code{64}, the large file interface
dfd2257a 155replaces the old interface. I.e., the functions are not made available
cf6960d7
UD
156under different names (as they are with @code{_LARGEFILE64_SOURCE}).
157Instead the old function names now reference the new functions, e.g., a
158call to @code{fseeko} now indeed calls @code{fseeko64}.
dfd2257a
UD
159
160This macro should only be selected if the system provides mechanisms for
161handling large files. On @w{64 bit} systems this macro has no effect
162since the @code{*64} functions are identical to the normal functions.
163
164This macro was introduced as part of the Large File Support extension
165(LFS).
310b3460 166@end defvr
dfd2257a 167
b4cbd371 168@defvr Macro _ISOC99_SOURCE
d08a7e4c 169@standards{GNU, (none)}
e8d190b9
RJ
170If this macro is defined, features from ISO C99 are included. Since
171these features are included by default, this macro is mostly relevant
172when the compiler uses an earlier language version.
b4cbd371
UD
173@end defvr
174
6a3962c4
RJ
175@defvr Macro _ISOC11_SOURCE
176@standards{C11, (none)}
177If this macro is defined, ISO C11 extensions to ISO C99 are included.
178@end defvr
179
48789000 180@defvr Macro __STDC_WANT_LIB_EXT2__
d08a7e4c 181@standards{ISO, (none)}
48789000
JM
182If you define this macro to the value @code{1}, features from ISO/IEC
183TR 24731-2:2010 (Dynamic Allocation Functions) are enabled. Only some
184of the features from this TR are supported by @theglibc{}.
185@end defvr
186
bf91be88 187@defvr Macro __STDC_WANT_IEC_60559_BFP_EXT__
d08a7e4c 188@standards{ISO, (none)}
bf91be88
JM
189If you define this macro, features from ISO/IEC TS 18661-1:2014
190(Floating-point extensions for C: Binary floating-point arithmetic)
191are enabled. Only some of the features from this TS are supported by
192@theglibc{}.
193@end defvr
194
412cb261 195@defvr Macro __STDC_WANT_IEC_60559_FUNCS_EXT__
d08a7e4c 196@standards{ISO, (none)}
412cb261
JM
197If you define this macro, features from ISO/IEC TS 18661-4:2015
198(Floating-point extensions for C: Supplementary functions) are
199enabled. Only some of the features from this TS are supported by
200@theglibc{}.
4fc12f0e
PM
201@end defvr
202
4fc12f0e 203@defvr Macro __STDC_WANT_IEC_60559_TYPES_EXT__
d08a7e4c 204@standards{ISO, (none)}
4fc12f0e
PM
205If you define this macro, features from ISO/IEC TS 18661-3:2015
206(Floating-point extensions for C: Interchange and extended types) are
207enabled. Only some of the features from this TS are supported by
208@theglibc{}.
412cb261
JM
209@end defvr
210
28f540f4 211@defvr Macro _GNU_SOURCE
d08a7e4c 212@standards{GNU, (none)}
b4cbd371
UD
213If you define this macro, everything is included: @w{ISO C89}, @w{ISO
214C99}, POSIX.1, POSIX.2, BSD, SVID, X/Open, LFS, and GNU extensions. In
215the cases where POSIX.1 conflicts with BSD, the POSIX definitions take
216precedence.
28f540f4
RM
217@end defvr
218
c688b419 219@defvr Macro _DEFAULT_SOURCE
d08a7e4c 220@standards{GNU, (none)}
c688b419 221If you define this macro, most features are included apart from
c941736c
JM
222X/Open, LFS and GNU extensions: the effect is to enable features from
223the 2008 edition of POSIX, as well as certain BSD and SVID features
862b4502
RJ
224without a separate feature test macro to control them.
225
226Be aware that compiler options also affect included features:
227
228@itemize
229@item
230If you use a strict conformance option, features beyond those from the
231compiler's language version will be disabled, though feature test
232macros may be used to enable them.
233
234@item
235Features enabled by compiler options are not overridden by feature
236test macros.
237@end itemize
c688b419
JM
238@end defvr
239
6a3962c4
RJ
240@defvr Macro _ATFILE_SOURCE
241@standards{GNU, (none)}
242If this macro is defined, additional @code{*at} interfaces are
243included.
244@end defvr
245
246@defvr Macro _FORTIFY_SOURCE
247@standards{GNU, (none)}
248If this macro is defined to @math{1}, security hardening is added to
249various library functions. If defined to @math{2}, even stricter
250checks are applied.
251@end defvr
252
26761c28
UD
253@defvr Macro _REENTRANT
254@defvrx Macro _THREAD_SAFE
88f9e739 255@standards{Obsolete, (none)}
c0307377
ZW
256These macros are obsolete. They have the same effect as defining
257@code{_POSIX_C_SOURCE} with the value @code{199506L}.
258
259Some very old C libraries required one of these macros to be defined
260for basic functionality (e.g.@: @code{getchar}) to be thread-safe.
ba1ffaa1
UD
261@end defvr
262
28f540f4 263We recommend you use @code{_GNU_SOURCE} in new programs. If you don't
c688b419
JM
264specify the @samp{-ansi} option to GCC, or other conformance options
265such as @option{-std=c99}, and don't define any of these macros
266explicitly, the effect is the same as defining @code{_DEFAULT_SOURCE}
267to 1.
28f540f4
RM
268
269When you define a feature test macro to request a larger class of features,
270it is harmless to define in addition a feature test macro for a subset of
271those features. For example, if you define @code{_POSIX_C_SOURCE}, then
272defining @code{_POSIX_SOURCE} as well has no effect. Likewise, if you
273define @code{_GNU_SOURCE}, then defining either @code{_POSIX_SOURCE} or
c941736c 274@code{_POSIX_C_SOURCE} as well has no effect.