Always define __USE_TIME_BITS64 when 64 bit time_t is used
[glibc.git] / manual / creature.texi
blobbe0a5ac7e6814b29777aa8af2fd9269682e4c95e
1 @node Feature Test Macros
2 @subsection Feature Test Macros
4 @cindex feature test macros
5 The exact set of features available when you compile a source file
6 is controlled by which @dfn{feature test macros} you define.
8 If you compile your programs using @samp{gcc -ansi}, you get only the
9 @w{ISO C} library features, unless you explicitly request additional
10 features by defining one or more of the feature macros.
11 @xref{Invoking GCC,, GNU CC Command Options, gcc, The GNU CC Manual},
12 for more information about GCC options.
14 You should define these macros by using @samp{#define} preprocessor
15 directives at the top of your source code files.  These directives
16 @emph{must} come before any @code{#include} of a system header file.  It
17 is best to make them the very first thing in the file, preceded only by
18 comments.  You could also use the @samp{-D} option to GCC, but it's
19 better if you make the source files indicate their own meaning in a
20 self-contained way.
22 This system exists to allow the library to conform to multiple standards.
23 Although the different standards are often described as supersets of each
24 other, they are usually incompatible because larger standards require
25 functions with names that smaller ones reserve to the user program.  This
26 is not mere pedantry --- it has been a problem in practice.  For instance,
27 some non-GNU programs define functions named @code{getline} that have
28 nothing to do with this library's @code{getline}.  They would not be
29 compilable if all features were enabled indiscriminately.
31 This should not be used to verify that a program conforms to a limited
32 standard.  It is insufficient for this purpose, as it will not protect you
33 from including header files outside the standard, or relying on semantics
34 undefined within the standard.
36 @defvr Macro _POSIX_SOURCE
37 @standards{POSIX.1, (none)}
38 If you define this macro, then the functionality from the POSIX.1
39 standard (IEEE Standard 1003.1) is available, as well as all of the
40 @w{ISO C} facilities.
42 The state of @code{_POSIX_SOURCE} is irrelevant if you define the
43 macro @code{_POSIX_C_SOURCE} to a positive integer.
44 @end defvr
46 @defvr Macro _POSIX_C_SOURCE
47 @standards{POSIX.2, (none)}
48 Define this macro to a positive integer to control which POSIX
49 functionality is made available.  The greater the value of this macro,
50 the more functionality is made available.
52 If you define this macro to a value greater than or equal to @code{1},
53 then the functionality from the 1990 edition of the POSIX.1 standard
54 (IEEE Standard 1003.1-1990) is made available.
56 If you define this macro to a value greater than or equal to @code{2},
57 then the functionality from the 1992 edition of the POSIX.2 standard
58 (IEEE Standard 1003.2-1992) is made available.
60 If you define this macro to a value greater than or equal to @code{199309L},
61 then the functionality from the 1993 edition of the POSIX.1b standard
62 (IEEE Standard 1003.1b-1993) is made available.
64 If you define this macro to a value greater than or equal to
65 @code{199506L}, then the functionality from the 1995 edition of the
66 POSIX.1c standard (IEEE Standard 1003.1c-1995) is made available.
68 If you define this macro to a value greater than or equal to
69 @code{200112L}, then the functionality from the 2001 edition of the
70 POSIX standard (IEEE Standard 1003.1-2001) is made available.
72 If you define this macro to a value greater than or equal to
73 @code{200809L}, then the functionality from the 2008 edition of the
74 POSIX standard (IEEE Standard 1003.1-2008) is made available.
76 Greater values for @code{_POSIX_C_SOURCE} will enable future extensions.
77 The POSIX standards process will define these values as necessary, and
78 @theglibc{} should support them some time after they become standardized.
79 The 1996 edition of POSIX.1 (ISO/IEC 9945-1: 1996) states that
80 if you define @code{_POSIX_C_SOURCE} to a value greater than
81 or equal to @code{199506L}, then the functionality from the 1996
82 edition is made available.  In general, in @theglibc{}, bugfixes to
83 the standards are included when specifying the base version; e.g.,
84 POSIX.1-2004 will always be included with a value of @code{200112L}.
85 @end defvr
87 @defvr Macro _XOPEN_SOURCE
88 @defvrx Macro _XOPEN_SOURCE_EXTENDED
89 @standards{X/Open, (none)}
90 If you define this macro, functionality described in the X/Open
91 Portability Guide is included.  This is a superset of the POSIX.1 and
92 POSIX.2 functionality and in fact @code{_POSIX_SOURCE} and
93 @code{_POSIX_C_SOURCE} are automatically defined.
95 As the unification of all Unices, functionality only available in
96 BSD and SVID is also included.
98 If the macro @code{_XOPEN_SOURCE_EXTENDED} is also defined, even more
99 functionality is available.  The extra functions will make all functions
100 available which are necessary for the X/Open Unix brand.
102 If the macro @code{_XOPEN_SOURCE} has the value @math{500} this includes
103 all functionality described so far plus some new definitions from the
104 Single Unix Specification, @w{version 2}.  The value @math{600}
105 (corresponding to the sixth revision) includes definitions from SUSv3,
106 and using @math{700} (the seventh revision) includes definitions from
107 SUSv4.
108 @end defvr
110 @defvr Macro _LARGEFILE_SOURCE
111 @standards{X/Open, (NONE)}
112 If this macro is defined some extra functions are available which
113 rectify a few shortcomings in all previous standards.  Specifically,
114 the functions @code{fseeko} and @code{ftello} are available.  Without
115 these 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.
119 This macro was introduced as part of the Large File Support extension (LFS).
120 @end defvr
122 @defvr Macro _LARGEFILE64_SOURCE
123 @standards{X/Open, (NONE)}
124 If you define this macro an additional set of functions is made available
125 which enables @w{32 bit} systems to use files of sizes beyond
126 the usual limit of 2GB.  This interface is not available if the system
127 does not support files that large.  On systems where the natural file
128 size limit is greater than 2GB (i.e., on @w{64 bit} systems) the new
129 functions are identical to the replaced functions.
131 The new functionality is made available by a new set of types and
132 functions which replace the existing ones.  The names of these new objects
133 contain @code{64} to indicate the intention, e.g., @code{off_t}
134 vs. @code{off64_t} and @code{fseeko} vs. @code{fseeko64}.
136 This macro was introduced as part of the Large File Support extension
137 (LFS).  It is a transition interface for the period when @w{64 bit}
138 offsets are not generally used (see @code{_FILE_OFFSET_BITS}).
139 @end defvr
141 @defvr Macro _FILE_OFFSET_BITS
142 @standards{X/Open, (NONE)}
143 This macro determines which file system interface shall be used, one
144 replacing the other.  Whereas @code{_LARGEFILE64_SOURCE} makes the @w{64
145 bit} interface available as an additional interface,
146 @code{_FILE_OFFSET_BITS} allows the @w{64 bit} interface to
147 replace the old interface.
149 If @code{_FILE_OFFSET_BITS} is defined to the
150 value @code{32}, the @w{32 bit} interface is used and
151 types like @code{off_t} have a size of @w{32 bits} on @w{32 bit}
152 systems.
154 If the macro is defined to the value @code{64}, the large file interface
155 replaces the old interface.  I.e., the functions are not made available
156 under different names (as they are with @code{_LARGEFILE64_SOURCE}).
157 Instead the old function names now reference the new functions, e.g., a
158 call to @code{fseeko} now indeed calls @code{fseeko64}.
160 If the macro is not defined it currently defaults to @code{32}, but
161 this default is planned to change due to a need to update
162 @code{time_t} for Y2038 safety, and applications should not rely on
163 the default.
165 This macro should only be selected if the system provides mechanisms for
166 handling large files.  On @w{64 bit} systems this macro has no effect
167 since the @code{*64} functions are identical to the normal functions.
169 This macro was introduced as part of the Large File Support extension
170 (LFS).
171 @end defvr
173 @defvr Macro _TIME_BITS
174 Define this macro to control the bit size of @code{time_t}, and therefore
175 the bit size of all @code{time_t}-derived types and the prototypes of all
176 related functions.
178 @enumerate
180 @item
181 If @code{_TIME_BITS} is undefined, the bit size of @code{time_t} is
182 architecture dependent.  Currently it defaults to 64 bits on most
183 architectures.  Although it defaults to 32 bits on some traditional
184 architectures (i686, ARM), this is planned to change and applications
185 should not rely on this.
187 @item
188 If @code{_TIME_BITS} is defined to be 64, @code{time_t} is defined
189 to be a 64-bit integer.  On platforms where @code{time_t} was
190 traditionally 32 bits, calls to proper syscalls depend on the
191 Linux kernel version on which the system is running. For Linux kernel
192 version above @b{5.1} syscalls supporting 64-bit time are used. Otherwise,
193 a fallback code is used with legacy (i.e. 32-bit) syscalls.
195 On such platforms, @theglibc{} will also define @code{__USE_TIME64_REDIRECTS}
196 to indicate whether the declarations are expanded to different ones
197 (either by redefiniding the symbol name or using symbol aliais).
198 For instance, if the symbol @code{clock_gettime} expands to
199 @code{__glock_gettime64}.
201 @item
202 If @code{_TIME_BITS} is defined to be 32, @code{time_t} is defined to
203 be a 32-bit integer where that is supported.  This is not recommended,
204 as 32-bit @code{time_t} stops working in the year 2038.
206 @item
207 For any other use case a compile-time error is emitted.
208 @end enumerate
210 @code{_TIME_BITS=64} can be defined only when
211 @code{_FILE_OFFSET_BITS=64} is also defined.
213 By using this macro certain ports gain support for 64-bit time and as
214 a result become immune to the Y2038 problem.
215 @end defvr
217 @defvr Macro _ISOC99_SOURCE
218 @standards{GNU, (none)}
219 If this macro is defined, features from ISO C99 are included.  Since
220 these features are included by default, this macro is mostly relevant
221 when the compiler uses an earlier language version.
222 @end defvr
224 @defvr Macro _ISOC11_SOURCE
225 @standards{C11, (none)}
226 If this macro is defined, ISO C11 extensions to ISO C99 are included.
227 @end defvr
229 @defvr Macro _ISOC23_SOURCE
230 @standards{C23, (none)}
231 If this macro is defined, ISO C23 extensions to ISO C11 are included.
232 Only some features from this draft standard are supported by
233 @theglibc{}.  The older name @code{_ISOC2X_SOURCE} is also supported.
234 @end defvr
236 @defvr Macro __STDC_WANT_LIB_EXT2__
237 @standards{ISO, (none)}
238 If you define this macro to the value @code{1}, features from ISO/IEC
239 TR 24731-2:2010 (Dynamic Allocation Functions) are enabled.  Only some
240 of the features from this TR are supported by @theglibc{}.
241 @end defvr
243 @defvr Macro __STDC_WANT_IEC_60559_BFP_EXT__
244 @standards{ISO, (none)}
245 If you define this macro, features from ISO/IEC TS 18661-1:2014
246 (Floating-point extensions for C: Binary floating-point arithmetic)
247 are enabled.  Only some of the features from this TS are supported by
248 @theglibc{}.
249 @end defvr
251 @defvr Macro __STDC_WANT_IEC_60559_FUNCS_EXT__
252 @standards{ISO, (none)}
253 If you define this macro, features from ISO/IEC TS 18661-4:2015
254 (Floating-point extensions for C: Supplementary functions) are
255 enabled.  Only some of the features from this TS are supported by
256 @theglibc{}.
257 @end defvr
259 @defvr Macro __STDC_WANT_IEC_60559_TYPES_EXT__
260 @standards{ISO, (none)}
261 If you define this macro, features from ISO/IEC TS 18661-3:2015
262 (Floating-point extensions for C: Interchange and extended types) are
263 enabled.  Only some of the features from this TS are supported by
264 @theglibc{}.
265 @end defvr
267 @defvr Macro __STDC_WANT_IEC_60559_EXT__
268 @standards{ISO, (none)}
269 If you define this macro, ISO C23 features defined in Annex F of that
270 standard are enabled.  This affects declarations of the
271 @code{totalorder} functions and functions related to NaN payloads.
272 @end defvr
274 @defvr Macro _GNU_SOURCE
275 @standards{GNU, (none)}
276 If you define this macro, everything is included: @w{ISO C89}, @w{ISO
277 C99}, POSIX.1, POSIX.2, BSD, SVID, X/Open, LFS, and GNU extensions.  In
278 the cases where POSIX.1 conflicts with BSD, the POSIX definitions take
279 precedence.
280 @end defvr
282 @defvr Macro _DEFAULT_SOURCE
283 @standards{GNU, (none)}
284 If you define this macro, most features are included apart from
285 X/Open, LFS and GNU extensions: the effect is to enable features from
286 the 2008 edition of POSIX, as well as certain BSD and SVID features
287 without a separate feature test macro to control them.
289 Be aware that compiler options also affect included features:
291 @itemize
292 @item
293 If you use a strict conformance option, features beyond those from the
294 compiler's language version will be disabled, though feature test
295 macros may be used to enable them.
297 @item
298 Features enabled by compiler options are not overridden by feature
299 test macros.
300 @end itemize
301 @end defvr
303 @defvr Macro _ATFILE_SOURCE
304 @standards{GNU, (none)}
305 If this macro is defined, additional @code{*at} interfaces are
306 included.
307 @end defvr
309 @defvr Macro _FORTIFY_SOURCE
310 @standards{GNU, (none)}
311 If this macro is defined to @math{1}, security hardening is added to
312 various library functions.  If defined to @math{2}, even stricter
313 checks are applied. If defined to @math{3}, @theglibc{} may also use
314 checks that may have an additional performance overhead.
315 @xref{Source Fortification,,Fortification of function calls}.
316 @end defvr
318 @defvr Macro _DYNAMIC_STACK_SIZE_SOURCE
319 @standards{GNU, (none)}
320 If this macro is defined, correct (but non compile-time constant)
321 MINSIGSTKSZ, SIGSTKSZ and PTHREAD_STACK_MIN are defined.
322 @end defvr
324 @defvr Macro _REENTRANT
325 @defvrx Macro _THREAD_SAFE
326 @standards{Obsolete, (none)}
327 These macros are obsolete.  They have the same effect as defining
328 @code{_POSIX_C_SOURCE} with the value @code{199506L}.
330 Some very old C libraries required one of these macros to be defined
331 for basic functionality (e.g.@: @code{getchar}) to be thread-safe.
332 @end defvr
334 We recommend you use @code{_GNU_SOURCE} in new programs.  If you don't
335 specify the @samp{-ansi} option to GCC, or other conformance options
336 such as @option{-std=c99}, and don't define any of these macros
337 explicitly, the effect is the same as defining @code{_DEFAULT_SOURCE}
338 to 1.
340 When you define a feature test macro to request a larger class of features,
341 it is harmless to define in addition a feature test macro for a subset of
342 those features.  For example, if you define @code{_POSIX_C_SOURCE}, then
343 defining @code{_POSIX_SOURCE} as well has no effect.  Likewise, if you
344 define @code{_GNU_SOURCE}, then defining either @code{_POSIX_SOURCE} or
345 @code{_POSIX_C_SOURCE} as well has no effect.