creature.texi 15 KB

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