Update.
[glibc.git] / manual / creature.texi
blob2e0c62e1f72ed78276b8dfa304928c4c8ace7917
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 @comment (none)
23 @comment POSIX.1
24 @defvr Macro _POSIX_SOURCE
25 If you define this macro, then the functionality from the POSIX.1
26 standard (IEEE Standard 1003.1) is available, as well as all of the
27 @w{ISO C} facilities.
28 @end defvr
30 @comment (none)
31 @comment POSIX.2
32 @defvr Macro _POSIX_C_SOURCE
33 If you define this macro with a value of @code{1}, then the
34 functionality from the POSIX.1 standard (IEEE Standard 1003.1) is made
35 available.  If you define this macro with a value of @code{2}, then both
36 the functionality from the POSIX.1 standard and the functionality from
37 the POSIX.2 standard (IEEE Standard 1003.2) are made available.  This is
38 in addition to the @w{ISO C} facilities.
39 @end defvr
41 @comment (none)
42 @comment GNU
43 @defvr Macro _BSD_SOURCE
44 If you define this macro, functionality derived from 4.3 BSD Unix is
45 included as well as the @w{ISO C}, POSIX.1, and POSIX.2 material.
47 Some of the features derived from 4.3 BSD Unix conflict with the
48 corresponding features specified by the POSIX.1 standard.  If this
49 macro is defined, the 4.3 BSD definitions take precedence over the
50 POSIX definitions.
52 Due to the nature of some of the conflicts between 4.3 BSD and POSIX.1,
53 you need to use a special @dfn{BSD compatibility library} when linking
54 programs compiled for BSD compatibility.  This is because some functions
55 must be defined in two different ways, one of them in the normal C
56 library, and one of them in the compatibility library.  If your program
57 defines @code{_BSD_SOURCE}, you must give the option @samp{-lbsd-compat}
58 to the compiler or linker when linking the program, to tell it to find
59 functions in this special compatibility library before looking for them in
60 the normal C library.
61 @pindex -lbsd-compat
62 @pindex bsd-compat
63 @cindex BSD compatibility library.
64 @end defvr
66 @comment (none)
67 @comment GNU
68 @defvr Macro _SVID_SOURCE
69 If you define this macro, functionality derived from SVID is
70 included as well as the @w{ISO C}, POSIX.1, POSIX.2, and X/Open material.
71 @end defvr
73 @comment (none)
74 @comment X/Open
75 @defvr Macro _XOPEN_SOURCE
76 @defvrx Macro _XOPEN_SOURCE_EXTENDED
77 If you define this macro, functionality described in the X/Open
78 Portability Guide is included.  This is a superset of the POSIX.1 and
79 POSIX.2 functionality and in fact @code{_POSIX_SOURCE} and
80 @code{_POSIX_C_SOURCE} are automatically defined.
82 As the unification of all Unices, functionality only available in
83 BSD and SVID is also included.
85 If the macro @code{_XOPEN_SOURCE_EXTENDED} is also defined, even more
86 functionality is available.  The extra functions will make all functions
87 available which are necessary for the X/Open Unix brand.
89 If the macro @code{_XOPEN_SOURCE} has the value @math{500} this includes
90 all functionality described so far plus some new definitions from the
91 Single Unix specification, @w{version 2}.
92 @end defvr
94 @comment (NONE)
95 @comment X/Open
96 @defvr Macro _LARGEFILE_SOURCE
97 If this macro is defined some extra functions are available which
98 rectify a few shortcomings in all previous standards.  More concreten
99 the functions @code{fseeko} and @code{ftello} are available.  Without
100 these functions the difference between the @w{ISO C} interface
101 (@code{fseek}, @code{ftell}) and the low-level POSIX interface
102 (@code{lseek}) would lead to problems.
104 This macro was introduced as part of the Large File Support extension (LFS).
105 @end defvr
107 @comment (NONE)
108 @comment X/Open
109 @defvar Macro _LARGEFILE64_SOURCE
110 If you define this macro an additional set of function gets available
111 which enables to use on @w{32 bit} systems to use files of sizes beyond
112 the usual limit of 2GB.  This interface is not available if the system
113 does not support files that large.  On systems where the natural file
114 size limit is greater than 2GB (i.e., on @w{64 bit} systems) the new
115 functions are identical to the replaced functions.
117 The new functionality is made available by a new set of types and
118 functions which replace existing.  The names of these new objects
119 contain @code{64} to indicate the intention, e.g., @code{off_t}
120 vs. @code{off64_t} and @code{fseeko} vs. @code{fseeko64}.
122 This macro was introduced as part of the Large File Support extension
123 (LFS).  It is a transition interface for the time @w{64 bit} offsets are
124 not generally used (see @code{_FILE_OFFSET_BITS}.
125 @end defvar
127 @comment (NONE)
128 @comment X/Open
129 @defvar _FILE_OFFSET_BITS
130 This macro lets decide which file system interface shall be used, one
131 replacing the other.  While @code{_LARGEFILE64_SOURCE} makes the @w{64
132 bit} interface available as an additional interface
133 @code{_FILE_OFFSET_BITS} allows to use the @w{64 bit} interface to
134 replace the old interface.
136 If @code{_FILE_OFFSET_BITS} is undefined or if it is defined to the
137 value @code{32} nothing changes.  The @w{32 bit} interface is used and
138 types like @code{off_t} have a size of @w{32 bits} on @w{32 bit}
139 systems.
141 If the macro is defined to the value @code{64} the large file interface
142 replaces the old interface.  I.e., the functions are not made available
143 under different names as @code{_LARGEFILE64_SOURCE} does.  Instead the
144 old function names now reference the new functions, e.g., a call to
145 @code{fseeko} now indeed calls @code{fseeko64}.
147 This macro should only be selected if the system provides mechanisms for
148 handling large files.  On @w{64 bit} systems this macro has no effect
149 since the @code{*64} functions are identical to the normal functions.
151 This macro was introduced as part of the Large File Support extension
152 (LFS).
153 @end defvar
155 @comment (none)
156 @comment GNU
157 @defvr Macro _GNU_SOURCE
158 If you define this macro, everything is included: @w{ISO C}, POSIX.1,
159 POSIX.2, BSD, SVID, X/Open, LFS, and GNU extensions.  In the cases where
160 POSIX.1 conflicts with BSD, the POSIX definitions take precedence.
162 If you want to get the full effect of @code{_GNU_SOURCE} but make the
163 BSD definitions take precedence over the POSIX definitions, use this
164 sequence of definitions:
166 @smallexample
167 #define _GNU_SOURCE
168 #define _BSD_SOURCE
169 #define _SVID_SOURCE
170 @end smallexample
172 Note that if you do this, you must link your program with the BSD
173 compatibility library by passing the @samp{-lbsd-compat} option to the
174 compiler or linker.  @strong{Note:} If you forget to do this, you may
175 get very strange errors at run time.
176 @end defvr
178 @comment (none)
179 @comment GNU
180 @defvr Macro _REENTRANT
181 @defvrx Macro _THREAD_SAFE
182 If you define one of these macros, reentrant versions of several functions get
183 declared.  Some of the functions are specified in POSIX.1c but many others
184 are only available on a few other systems or are unique to GNU libc.
185 The problem is that the standardization of the thread safe C library
186 interface still is behind.
188 Unlike on some other systems no special version of the C library must be
189 used for linking.  There is only one version but while compiling this
190 it must have been specified to compile as thread safe.
191 @end defvr
193 We recommend you use @code{_GNU_SOURCE} in new programs.  If you don't
194 specify the @samp{-ansi} option to GCC and don't define any of these
195 macros explicitly, the effect is the same as defining
196 @code{_POSIX_C_SOURCE} to 2 and @code{_POSIX_SOURCE},
197 @code{_SVID_SOURCE}, and @code{_BSD_SOURCE} to 1.
199 When you define a feature test macro to request a larger class of features,
200 it is harmless to define in addition a feature test macro for a subset of
201 those features.  For example, if you define @code{_POSIX_C_SOURCE}, then
202 defining @code{_POSIX_SOURCE} as well has no effect.  Likewise, if you
203 define @code{_GNU_SOURCE}, then defining either @code{_POSIX_SOURCE} or
204 @code{_POSIX_C_SOURCE} or @code{_SVID_SOURCE} as well has no effect.
206 Note, however, that the features of @code{_BSD_SOURCE} are not a subset of
207 any of the other feature test macros supported.  This is because it defines
208 BSD features that take precedence over the POSIX features that are
209 requested by the other macros.  For this reason, defining
210 @code{_BSD_SOURCE} in addition to the other feature test macros does have
211 an effect: it causes the BSD features to take priority over the conflicting
212 POSIX features.