Support __STDC_WANT_IEC_60559_FUNCS_EXT__ feature test macro.
[glibc.git] / manual / creature.texi
blob257f8718b179c9e3392a60fca94ed71e68c289aa
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.info, The GNU CC Manual},
12 for more information about GCC options.@refill
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 @comment (none)
37 @comment POSIX.1
38 @defvr Macro _POSIX_SOURCE
39 If you define this macro, then the functionality from the POSIX.1
40 standard (IEEE Standard 1003.1) is available, as well as all of the
41 @w{ISO C} facilities.
43 The state of @code{_POSIX_SOURCE} is irrelevant if you define the
44 macro @code{_POSIX_C_SOURCE} to a positive integer.
45 @end defvr
47 @comment (none)
48 @comment POSIX.2
49 @defvr Macro _POSIX_C_SOURCE
50 Define this macro to a positive integer to control which POSIX
51 functionality is made available.  The greater the value of this macro,
52 the more functionality is made available.
54 If you define this macro to a value greater than or equal to @code{1},
55 then the functionality from the 1990 edition of the POSIX.1 standard
56 (IEEE Standard 1003.1-1990) is made available.
58 If you define this macro to a value greater than or equal to @code{2},
59 then the functionality from the 1992 edition of the POSIX.2 standard
60 (IEEE Standard 1003.2-1992) is made available.
62 If you define this macro to a value greater than or equal to @code{199309L},
63 then the functionality from the 1993 edition of the POSIX.1b standard
64 (IEEE Standard 1003.1b-1993) is made available.
66 Greater values for @code{_POSIX_C_SOURCE} will enable future extensions.
67 The POSIX standards process will define these values as necessary, and
68 @theglibc{} should support them some time after they become standardized.
69 The 1996 edition of POSIX.1 (ISO/IEC 9945-1: 1996) states that
70 if you define @code{_POSIX_C_SOURCE} to a value greater than
71 or equal to @code{199506L}, then the functionality from the 1996
72 edition is made available.
73 @end defvr
75 @comment (none)
76 @comment X/Open
77 @defvr Macro _XOPEN_SOURCE
78 @comment (none)
79 @comment X/Open
80 @defvrx Macro _XOPEN_SOURCE_EXTENDED
81 If you define this macro, functionality described in the X/Open
82 Portability Guide is included.  This is a superset of the POSIX.1 and
83 POSIX.2 functionality and in fact @code{_POSIX_SOURCE} and
84 @code{_POSIX_C_SOURCE} are automatically defined.
86 As the unification of all Unices, functionality only available in
87 BSD and SVID is also included.
89 If the macro @code{_XOPEN_SOURCE_EXTENDED} is also defined, even more
90 functionality is available.  The extra functions will make all functions
91 available which are necessary for the X/Open Unix brand.
93 If the macro @code{_XOPEN_SOURCE} has the value @math{500} this includes
94 all functionality described so far plus some new definitions from the
95 Single Unix Specification, @w{version 2}.
96 @end defvr
98 @comment (NONE)
99 @comment X/Open
100 @defvr Macro _LARGEFILE_SOURCE
101 If this macro is defined some extra functions are available which
102 rectify a few shortcomings in all previous standards.  Specifically,
103 the functions @code{fseeko} and @code{ftello} are available.  Without
104 these functions the difference between the @w{ISO C} interface
105 (@code{fseek}, @code{ftell}) and the low-level POSIX interface
106 (@code{lseek}) would lead to problems.
108 This macro was introduced as part of the Large File Support extension (LFS).
109 @end defvr
111 @comment (NONE)
112 @comment X/Open
113 @defvr Macro _LARGEFILE64_SOURCE
114 If you define this macro an additional set of functions is made available
115 which enables @w{32 bit} systems to use files of sizes beyond
116 the usual limit of 2GB.  This interface is not available if the system
117 does not support files that large.  On systems where the natural file
118 size limit is greater than 2GB (i.e., on @w{64 bit} systems) the new
119 functions are identical to the replaced functions.
121 The new functionality is made available by a new set of types and
122 functions which replace the existing ones.  The names of these new objects
123 contain @code{64} to indicate the intention, e.g., @code{off_t}
124 vs. @code{off64_t} and @code{fseeko} vs. @code{fseeko64}.
126 This macro was introduced as part of the Large File Support extension
127 (LFS).  It is a transition interface for the period when @w{64 bit}
128 offsets are not generally used (see @code{_FILE_OFFSET_BITS}).
129 @end defvr
131 @comment (NONE)
132 @comment X/Open
133 @defvr Macro _FILE_OFFSET_BITS
134 This macro determines which file system interface shall be used, one
135 replacing the other.  Whereas @code{_LARGEFILE64_SOURCE} makes the @w{64
136 bit} interface available as an additional interface,
137 @code{_FILE_OFFSET_BITS} allows the @w{64 bit} interface to
138 replace the old interface.
140 If @code{_FILE_OFFSET_BITS} is undefined, or if it is defined to the
141 value @code{32}, nothing changes.  The @w{32 bit} interface is used and
142 types like @code{off_t} have a size of @w{32 bits} on @w{32 bit}
143 systems.
145 If the macro is defined to the value @code{64}, the large file interface
146 replaces the old interface.  I.e., the functions are not made available
147 under different names (as they are with @code{_LARGEFILE64_SOURCE}).
148 Instead the old function names now reference the new functions, e.g., a
149 call to @code{fseeko} now indeed calls @code{fseeko64}.
151 This macro should only be selected if the system provides mechanisms for
152 handling large files.  On @w{64 bit} systems this macro has no effect
153 since the @code{*64} functions are identical to the normal functions.
155 This macro was introduced as part of the Large File Support extension
156 (LFS).
157 @end defvr
159 @comment (none)
160 @comment GNU
161 @defvr Macro _ISOC99_SOURCE
162 Until the revised @w{ISO C} standard is widely adopted the new features
163 are not automatically enabled.  @Theglibc{} nevertheless has a complete
164 implementation of the new standard and to enable the new features the
165 macro @code{_ISOC99_SOURCE} should be defined.
166 @end defvr
168 @comment (none)
169 @comment ISO
170 @defvr Macro __STDC_WANT_LIB_EXT2__
171 If you define this macro to the value @code{1}, features from ISO/IEC
172 TR 24731-2:2010 (Dynamic Allocation Functions) are enabled.  Only some
173 of the features from this TR are supported by @theglibc{}.
174 @end defvr
176 @comment (none)
177 @comment ISO
178 @defvr Macro __STDC_WANT_IEC_60559_BFP_EXT__
179 If you define this macro, features from ISO/IEC TS 18661-1:2014
180 (Floating-point extensions for C: Binary floating-point arithmetic)
181 are enabled.  Only some of the features from this TS are supported by
182 @theglibc{}.
183 @end defvr
185 @comment (none)
186 @comment ISO
187 @defvr Macro __STDC_WANT_IEC_60559_FUNCS_EXT__
188 If you define this macro, features from ISO/IEC TS 18661-4:2015
189 (Floating-point extensions for C: Supplementary functions) are
190 enabled.  Only some of the features from this TS are supported by
191 @theglibc{}.
192 @end defvr
194 @comment (none)
195 @comment GNU
196 @defvr Macro _GNU_SOURCE
197 If you define this macro, everything is included: @w{ISO C89}, @w{ISO
198 C99}, POSIX.1, POSIX.2, BSD, SVID, X/Open, LFS, and GNU extensions.  In
199 the cases where POSIX.1 conflicts with BSD, the POSIX definitions take
200 precedence.
201 @end defvr
203 @comment (none)
204 @comment GNU
205 @defvr Macro _DEFAULT_SOURCE
206 If you define this macro, most features are included apart from
207 X/Open, LFS and GNU extensions: the effect is to enable features from
208 the 2008 edition of POSIX, as well as certain BSD and SVID features
209 without a separate feature test macro to control them.  Defining this
210 macro, on its own and without using compiler options such as
211 @option{-ansi} or @option{-std=c99}, has the same effect as not
212 defining any feature test macros; defining it together with other
213 feature test macros, or when options such as @option{-ansi} are used,
214 enables those features even when the other options would otherwise
215 cause them to be disabled.
216 @end defvr
218 @comment (none)
219 @comment GNU
220 @defvr Macro _REENTRANT
221 @defvrx Macro _THREAD_SAFE
222 If you define one of these macros, reentrant versions of several functions get
223 declared.  Some of the functions are specified in POSIX.1c but many others
224 are only available on a few other systems or are unique to @theglibc{}.
225 The problem is the delay in the standardization of the thread safe C library
226 interface.
228 Unlike on some other systems, no special version of the C library must be
229 used for linking.  There is only one version but while compiling this
230 it must have been specified to compile as thread safe.
231 @end defvr
233 We recommend you use @code{_GNU_SOURCE} in new programs.  If you don't
234 specify the @samp{-ansi} option to GCC, or other conformance options
235 such as @option{-std=c99}, and don't define any of these macros
236 explicitly, the effect is the same as defining @code{_DEFAULT_SOURCE}
237 to 1.
239 When you define a feature test macro to request a larger class of features,
240 it is harmless to define in addition a feature test macro for a subset of
241 those features.  For example, if you define @code{_POSIX_C_SOURCE}, then
242 defining @code{_POSIX_SOURCE} as well has no effect.  Likewise, if you
243 define @code{_GNU_SOURCE}, then defining either @code{_POSIX_SOURCE} or
244 @code{_POSIX_C_SOURCE} as well has no effect.