Document use of CC and CFLAGS in more detail (bug 20980, bug 21234).
[glibc.git] / manual / creature.texi
blob2e059587566833f7de16fba6d0ca1a05a8f76c94
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.@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 @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 Greater values for @code{_POSIX_C_SOURCE} will enable future extensions.
65 The POSIX standards process will define these values as necessary, and
66 @theglibc{} should support them some time after they become standardized.
67 The 1996 edition of POSIX.1 (ISO/IEC 9945-1: 1996) states that
68 if you define @code{_POSIX_C_SOURCE} to a value greater than
69 or equal to @code{199506L}, then the functionality from the 1996
70 edition is made available.
71 @end defvr
73 @defvr Macro _XOPEN_SOURCE
74 @defvrx Macro _XOPEN_SOURCE_EXTENDED
75 @standards{X/Open, (none)}
76 If you define this macro, functionality described in the X/Open
77 Portability Guide is included.  This is a superset of the POSIX.1 and
78 POSIX.2 functionality and in fact @code{_POSIX_SOURCE} and
79 @code{_POSIX_C_SOURCE} are automatically defined.
81 As the unification of all Unices, functionality only available in
82 BSD and SVID is also included.
84 If the macro @code{_XOPEN_SOURCE_EXTENDED} is also defined, even more
85 functionality is available.  The extra functions will make all functions
86 available which are necessary for the X/Open Unix brand.
88 If the macro @code{_XOPEN_SOURCE} has the value @math{500} this includes
89 all functionality described so far plus some new definitions from the
90 Single Unix Specification, @w{version 2}.
91 @end defvr
93 @defvr Macro _LARGEFILE_SOURCE
94 @standards{X/Open, (NONE)}
95 If this macro is defined some extra functions are available which
96 rectify a few shortcomings in all previous standards.  Specifically,
97 the functions @code{fseeko} and @code{ftello} are available.  Without
98 these functions the difference between the @w{ISO C} interface
99 (@code{fseek}, @code{ftell}) and the low-level POSIX interface
100 (@code{lseek}) would lead to problems.
102 This macro was introduced as part of the Large File Support extension (LFS).
103 @end defvr
105 @defvr Macro _LARGEFILE64_SOURCE
106 @standards{X/Open, (NONE)}
107 If you define this macro an additional set of functions is made available
108 which enables @w{32 bit} systems to use files of sizes beyond
109 the usual limit of 2GB.  This interface is not available if the system
110 does not support files that large.  On systems where the natural file
111 size limit is greater than 2GB (i.e., on @w{64 bit} systems) the new
112 functions are identical to the replaced functions.
114 The new functionality is made available by a new set of types and
115 functions which replace the existing ones.  The names of these new objects
116 contain @code{64} to indicate the intention, e.g., @code{off_t}
117 vs. @code{off64_t} and @code{fseeko} vs. @code{fseeko64}.
119 This macro was introduced as part of the Large File Support extension
120 (LFS).  It is a transition interface for the period when @w{64 bit}
121 offsets are not generally used (see @code{_FILE_OFFSET_BITS}).
122 @end defvr
124 @defvr Macro _FILE_OFFSET_BITS
125 @standards{X/Open, (NONE)}
126 This macro determines which file system interface shall be used, one
127 replacing the other.  Whereas @code{_LARGEFILE64_SOURCE} makes the @w{64
128 bit} interface available as an additional interface,
129 @code{_FILE_OFFSET_BITS} allows the @w{64 bit} interface to
130 replace the old interface.
132 If @code{_FILE_OFFSET_BITS} is undefined, or if it is defined to the
133 value @code{32}, nothing changes.  The @w{32 bit} interface is used and
134 types like @code{off_t} have a size of @w{32 bits} on @w{32 bit}
135 systems.
137 If the macro is defined to the value @code{64}, the large file interface
138 replaces the old interface.  I.e., the functions are not made available
139 under different names (as they are with @code{_LARGEFILE64_SOURCE}).
140 Instead the old function names now reference the new functions, e.g., a
141 call to @code{fseeko} now indeed calls @code{fseeko64}.
143 This macro should only be selected if the system provides mechanisms for
144 handling large files.  On @w{64 bit} systems this macro has no effect
145 since the @code{*64} functions are identical to the normal functions.
147 This macro was introduced as part of the Large File Support extension
148 (LFS).
149 @end defvr
151 @defvr Macro _ISOC99_SOURCE
152 @standards{GNU, (none)}
153 Until the revised @w{ISO C} standard is widely adopted the new features
154 are not automatically enabled.  @Theglibc{} nevertheless has a complete
155 implementation of the new standard and to enable the new features the
156 macro @code{_ISOC99_SOURCE} should be defined.
157 @end defvr
159 @defvr Macro __STDC_WANT_LIB_EXT2__
160 @standards{ISO, (none)}
161 If you define this macro to the value @code{1}, features from ISO/IEC
162 TR 24731-2:2010 (Dynamic Allocation Functions) are enabled.  Only some
163 of the features from this TR are supported by @theglibc{}.
164 @end defvr
166 @defvr Macro __STDC_WANT_IEC_60559_BFP_EXT__
167 @standards{ISO, (none)}
168 If you define this macro, features from ISO/IEC TS 18661-1:2014
169 (Floating-point extensions for C: Binary floating-point arithmetic)
170 are enabled.  Only some of the features from this TS are supported by
171 @theglibc{}.
172 @end defvr
174 @defvr Macro __STDC_WANT_IEC_60559_FUNCS_EXT__
175 @standards{ISO, (none)}
176 If you define this macro, features from ISO/IEC TS 18661-4:2015
177 (Floating-point extensions for C: Supplementary functions) are
178 enabled.  Only some of the features from this TS are supported by
179 @theglibc{}.
180 @end defvr
182 @defvr Macro __STDC_WANT_IEC_60559_TYPES_EXT__
183 @standards{ISO, (none)}
184 If you define this macro, features from ISO/IEC TS 18661-3:2015
185 (Floating-point extensions for C: Interchange and extended types) are
186 enabled.  Only some of the features from this TS are supported by
187 @theglibc{}.
188 @end defvr
190 @defvr Macro _GNU_SOURCE
191 @standards{GNU, (none)}
192 If you define this macro, everything is included: @w{ISO C89}, @w{ISO
193 C99}, POSIX.1, POSIX.2, BSD, SVID, X/Open, LFS, and GNU extensions.  In
194 the cases where POSIX.1 conflicts with BSD, the POSIX definitions take
195 precedence.
196 @end defvr
198 @defvr Macro _DEFAULT_SOURCE
199 @standards{GNU, (none)}
200 If you define this macro, most features are included apart from
201 X/Open, LFS and GNU extensions: the effect is to enable features from
202 the 2008 edition of POSIX, as well as certain BSD and SVID features
203 without a separate feature test macro to control them.  Defining this
204 macro, on its own and without using compiler options such as
205 @option{-ansi} or @option{-std=c99}, has the same effect as not
206 defining any feature test macros; defining it together with other
207 feature test macros, or when options such as @option{-ansi} are used,
208 enables those features even when the other options would otherwise
209 cause them to be disabled.
210 @end defvr
212 @defvr Macro _REENTRANT
213 @defvrx Macro _THREAD_SAFE
214 @standards{Obsolete, (none)}
215 These macros are obsolete.  They have the same effect as defining
216 @code{_POSIX_C_SOURCE} with the value @code{199506L}.
218 Some very old C libraries required one of these macros to be defined
219 for basic functionality (e.g.@: @code{getchar}) to be thread-safe.
220 @end defvr
222 We recommend you use @code{_GNU_SOURCE} in new programs.  If you don't
223 specify the @samp{-ansi} option to GCC, or other conformance options
224 such as @option{-std=c99}, and don't define any of these macros
225 explicitly, the effect is the same as defining @code{_DEFAULT_SOURCE}
226 to 1.
228 When you define a feature test macro to request a larger class of features,
229 it is harmless to define in addition a feature test macro for a subset of
230 those features.  For example, if you define @code{_POSIX_C_SOURCE}, then
231 defining @code{_POSIX_SOURCE} as well has no effect.  Likewise, if you
232 define @code{_GNU_SOURCE}, then defining either @code{_POSIX_SOURCE} or
233 @code{_POSIX_C_SOURCE} as well has no effect.