{"id":3946,"date":"2022-12-20T17:28:29","date_gmt":"2022-12-20T20:28:29","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/feature_test_macros-man7\/"},"modified":"2022-12-20T17:28:29","modified_gmt":"2022-12-20T20:28:29","slug":"feature_test_macros-man7","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/feature_test_macros-man7\/","title":{"rendered":"FEATURE_TEST_MACROS (man7)"},"content":{"rendered":"<h1 align=\"center\">FEATURE_TEST_MACROS<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#CONFORMING TO\">CONFORMING TO<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COLOPHON\">COLOPHON<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">feature_test_macros \u2212 feature test macros<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Feature test macros allow the programmer to control the definitions that are exposed by system header files when a program is compiled.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>NOTE:<\/b> In order to be effective, a feature test macro <i>must be defined before including any header files<\/i>. This can be done either in the compilation command (<i>cc \u2212DMACRO=value<\/i>) or by defining the macro within the source code before including any headers. The requirement that the macro must be defined before including any header file exists because header files may freely include one another. Thus, for example, in the following lines, defining the <b>_GNU_SOURCE<\/b> macro may have no effect because the header <i><abc.h><\/i> itself includes <i><xyz.h><\/i> (POSIX explicitly allows this):<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">#include <abc.h> <br \/> #define _GNU_SOURCE <br \/> #include <xyz.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Some feature test macros are useful for creating portable applications, by preventing nonstandard definitions from being exposed. Other macros can be used to expose nonstandard definitions that are not exposed by default.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The precise effects of each of the feature test macros described below can be ascertained by inspecting the <i><features.h><\/i> header file. <b>Note<\/b>: applications do <i>not<\/i> need to directly include <i><features.h><\/i>; indeed, doing so is actively discouraged. See NOTES.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Specification of feature test macro requirements in manual pages<\/b> <br \/> When a function requires that a feature test macro is defined, the manual page SYNOPSIS typically includes a note of the following form (this example from the <b>acct<\/b>(2) manual page):<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>#include <unistd.h><\/b><\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>int acct(const char *<\/b><i>filename<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:15%; margin-top: 1em\">Feature Test Macro Requirements for glibc (see <b><br \/> feature_test_macros<\/b>(7)):<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>acct<\/b>(): _BSD_SOURCE || (_XOPEN_SOURCE &#038;&#038; _XOPEN_SOURCE\u00a0<\u00a0500)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>||<\/b> means that in order to obtain the declaration of <b>acct<\/b>(2) from <i><unistd.h><\/i>, <i>either<\/i> of the following macro definitions must be made before including any header files:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">#define _BSD_SOURCE <br \/> #define _XOPEN_SOURCE \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var or any value < 500 *\/<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Alternatively, equivalent definitions can be included in the compilation command:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">cc \u2212D_BSD_SOURCE <br \/> cc \u2212D_XOPEN_SOURCE # Or any value < 500<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Note that, as described below, <b>some feature test macros are defined by default<\/b>, so that it may not always be necessary to explicitly specify the feature test macro(s) shown in the SYNOPSIS.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In a few cases, manual pages use a shorthand for expressing the feature test macro requirements (this example from <b>readahead<\/b>(2)):<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b>#define _GNU_SOURCE <br \/> #include <fcntl.h><\/b><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b>ssize_t readahead(int<\/b> <i>fd<\/i><b>, off64_t *<\/b><i>offset<\/i><b>, size_t<\/b> <i>count<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This format is employed in cases where only a single feature test macro can be used to expose the function declaration, and that macro is not defined by default.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Feature test macros understood by glibc<\/b> <br \/> The paragraphs below explain how feature test macros are handled in Linux glibc 2.<i>x<\/i>, <i>x<\/i> > 0.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">First, though a summary of a few details for the impatient:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"85%\">\n<p>The macros that you most likely need to use in modern source code are <b>_POSIX_C_SOURCE<\/b> (for definitions from various versions of POSIX.1), <b>_XOPEN_SOURCE<\/b> (for definitions from various versions of SUS), <b>_GNU_SOURCE<\/b> (for GNU and\/or Linux specific stuff), and <b>_DEFAULT_SOURCE<\/b> (to get definitions that would normally be provided by default).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"85%\">\n<p>Certain macros are defined with default values. Thus, although one or more macros may be indicated as being required in the SYNOPSIS of a man page, it may not be necessary to define them explicitly. Full details of the defaults are given later in this man page.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"85%\">\n<p>Defining <b>_XOPEN_SOURCE<\/b> with a value of 600 or greater produces the same effects as defining <b>_POSIX_C_SOURCE<\/b> with a value of 200112L or greater. Where one sees<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%; margin-top: 1em\">_POSIX_C_SOURCE >= 200112L<\/p>\n<p style=\"margin-left:15%; margin-top: 1em\">in the feature test macro requirements in the SYNOPSIS of a man page, it is implicit that the following has the same effect:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">_XOPEN_SOURCE >= 600<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"85%\">\n<p style=\"margin-top: 1em\">Defining <b>_XOPEN_SOURCE<\/b> with a value of 700 or greater produces the same effects as defining <b>_POSIX_C_SOURCE<\/b> with a value of 200809L or greater. Where one sees<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%; margin-top: 1em\">_POSIX_C_SOURCE >= 200809L<\/p>\n<p style=\"margin-left:15%; margin-top: 1em\">in the feature test macro requirements in the SYNOPSIS of a man page, it is implicit that the following has the same effect:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">_XOPEN_SOURCE >= 700<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Linux glibc understands the following feature test macros: <b><br \/> __STRICT_ANSI__<\/b><\/p>\n<p style=\"margin-left:22%;\">ISO Standard C. This macro is implicitly defined by <b>gcc<\/b>(1) when invoked with, for example, the <i>\u2212std=c99<\/i> or <i>\u2212ansi<\/i> flag.<\/p>\n<p style=\"margin-left:11%;\"><b>_POSIX_C_SOURCE<\/b><\/p>\n<p style=\"margin-left:22%;\">Defining this macro causes header files to expose definitions as follows:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>The value 1 exposes definitions conforming to POSIX.1-1990 and ISO C (1990).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>The value 2 or greater additionally exposes definitions for POSIX.2-1992.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>The value 199309L or greater additionally exposes definitions for POSIX.1b (real-time extensions).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>The value 199506L or greater additionally exposes definitions for POSIX.1c (threads).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>(Since glibc 2.3.3) The value 200112L or greater additionally exposes definitions corresponding to the POSIX.1-2001 base specification (excluding the XSI extension). This value also causes C95 (since glibc 2.12) and C99 (since glibc 2.10) features to be exposed (in other words, the equivalent of defining <b>_ISOC99_SOURCE<\/b>).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>(Since glibc 2.10) The value 200809L or greater additionally exposes definitions corresponding to the POSIX.1-2008 base specification (excluding the XSI extension).<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>_POSIX_SOURCE<\/b><\/p>\n<p style=\"margin-left:22%;\">Defining this obsolete macro with any value is equivalent to defining <b>_POSIX_C_SOURCE<\/b> with the value 1.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Since this macro is obsolete, its usage is generally not documented when discussing feature test macro requirements in the man pages.<\/p>\n<p style=\"margin-left:11%;\"><b>_XOPEN_SOURCE<\/b><\/p>\n<p style=\"margin-left:22%;\">Defining this macro causes header files to expose definitions as follows:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>Defining with any value exposes definitions conforming to POSIX.1, POSIX.2, and XPG4.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>The value 500 or greater additionally exposes definitions for SUSv2 (UNIX 98).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>(Since glibc 2.2) The value 600 or greater additionally exposes definitions for SUSv3 (UNIX 03; i.e., the POSIX.1-2001 base specification plus the XSI extension) and C99 definitions.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p>(Since glibc 2.10) The value 700 or greater additionally exposes definitions for SUSv4 (i.e., the POSIX.1-2008 base specification plus the XSI extension).<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:22%; margin-top: 1em\">If <b>__STRICT_ANSI__<\/b> is not defined, or <b>_XOPEN_SOURCE<\/b> is defined with a value greater than or equal to 500 <i>and<\/i> neither <b>_POSIX_SOURCE<\/b> nor <b>_POSIX_C_SOURCE<\/b> is explicitly defined, then the following macros are implicitly defined:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p style=\"margin-top: 1em\">\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p style=\"margin-top: 1em\"><b>_POSIX_SOURCE<\/b> is defined with the value 1.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"22%\"><\/td>\n<td width=\"1%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"74%\">\n<p><b>_POSIX_C_SOURCE<\/b> is defined, according to the value of <b>_XOPEN_SOURCE<\/b>:<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:26%;\"><b>_XOPEN_SOURCE<\/b> < 500<\/p>\n<p style=\"margin-left:37%;\"><b>_POSIX_C_SOURCE<\/b> is defined with the value 2.<\/p>\n<p style=\"margin-left:26%;\">500 <= <b>_XOPEN_SOURCE<\/b> < 600<\/p>\n<p style=\"margin-left:37%;\"><b>_POSIX_C_SOURCE<\/b> is defined with the value 199506L.<\/p>\n<p style=\"margin-left:26%;\">600 <= <b>_XOPEN_SOURCE<\/b> < 700<\/p>\n<p style=\"margin-left:37%;\"><b>_POSIX_C_SOURCE<\/b> is defined with the value 200112L.<\/p>\n<p style=\"margin-left:26%;\">700 <= <b>_XOPEN_SOURCE<\/b> (since glibc 2.10)<\/p>\n<p style=\"margin-left:37%;\"><b>_POSIX_C_SOURCE<\/b> is defined with the value 200809L.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">In addition, defining <b>_XOPEN_SOURCE<\/b> with a value of 500 or greater produces the same effects as defining <b>_XOPEN_SOURCE_EXTENDED<\/b>.<\/p>\n<p style=\"margin-left:11%;\"><b>_XOPEN_SOURCE_EXTENDED<\/b><\/p>\n<p style=\"margin-left:22%;\">If this macro is defined, <i>and<\/i> <b>_XOPEN_SOURCE<\/b> is defined, then expose definitions corresponding to the XPG4v2 (SUSv1) UNIX extensions (UNIX 95). Defining <b>_XOPEN_SOURCE<\/b> with a value of 500 or more also produces the same effect as defining <b>_XOPEN_SOURCE_EXTENDED<\/b>. Use of <b>_XOPEN_SOURCE_EXTENDED<\/b> in new source code should be avoided.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Since defining <b>_XOPEN_SOURCE<\/b> with a value of 500 or more has the same effect as defining <b>_XOPEN_SOURCE_EXTENDED<\/b>, the latter (obsolete) feature test macro is generally not described in the SYNOPSIS in man pages.<\/p>\n<p style=\"margin-left:11%;\"><b>_ISOC99_SOURCE<\/b> (since glibc 2.1.3)<\/p>\n<p style=\"margin-left:22%;\">Exposes declarations consistent with the ISO C99 standard.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Earlier glibc 2.1.x versions recognized an equivalent macro named <b>_ISOC9X_SOURCE<\/b> (because the C99 standard had not then been finalized). Although the use of this macro is obsolete, glibc continues to recognize it for backward compatibility.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Defining <b>_ISOC99_SOURCE<\/b> also exposes ISO C (1990) Amendment 1 (&#8220;C95&#8221;) definitions. (The primary change in C95 was support for international character sets.)<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Invoking the C compiler with the option <i>\u2212std=c99<\/i> produces the same effects as defining this macro.<\/p>\n<p style=\"margin-left:11%;\"><b>_ISOC11_SOURCE<\/b> (since glibc 2.16)<\/p>\n<p style=\"margin-left:22%;\">Exposes declarations consistent with the ISO C11 standard. Defining this macro also enables C99 and C95 features (like <b>_ISOC99_SOURCE<\/b>).<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Invoking the C compiler with the option <i>\u2212std=c11<\/i> produces the same effects as defining this macro.<\/p>\n<p style=\"margin-left:11%;\"><b>_LARGEFILE64_SOURCE<\/b><\/p>\n<p style=\"margin-left:22%;\">Expose definitions for the alternative API specified by the LFS (Large File Summit) as a &#8220;transitional extension&#8221; to the Single UNIX Specification. (See <a href=\"http:\/\/opengroup.org\/platform\/lfs.html\">http:\/\/opengroup.org\/platform\/lfs.html<\/a>.) The alternative API consists of a set of new objects (i.e., functions and types) whose names are suffixed with &#8220;64&#8221; (e.g., <i>off64_t<\/i> versus <i>off_t<\/i>, <b>lseek64<\/b>() versus <b>lseek<\/b>(), etc.). New programs should not employ this macro; instead <i>_FILE_OFFSET_BITS=64<\/i> should be employed.<\/p>\n<p style=\"margin-left:11%;\"><b>_LARGEFILE_SOURCE<\/b><\/p>\n<p style=\"margin-left:22%;\">This macro was historically used to expose certain functions (specifically <b>fseeko<\/b>(3) and <b>ftello<\/b>(3)) that address limitations of earlier APIs (<b>fseek<\/b>(3) and <b>ftell<\/b>(3)) that use <i>long<\/i> for file offsets. This macro is implicitly defined if <b>_XOPEN_SOURCE<\/b> is defined with a value greater than or equal to 500. New programs should not employ this macro; defining <b>_XOPEN_SOURCE<\/b> as just described or defining <b>_FILE_OFFSET_BITS<\/b> with the value 64 is the preferred mechanism to achieve the same result.<\/p>\n<p style=\"margin-left:11%;\"><b>_FILE_OFFSET_BITS<\/b><\/p>\n<p style=\"margin-left:22%;\">Defining this macro with the value 64 automatically converts references to 32-bit functions and data types related to file I\/O and filesystem operations into references to their 64-bit counterparts. This is useful for performing I\/O on large files (> 2 Gigabytes) on 32-bit systems. (Defining this macro permits correctly written programs to use large files with only a recompilation being required.)<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">64-bit systems naturally permit file sizes greater than 2 Gigabytes, and on those systems this macro has no effect.<\/p>\n<p style=\"margin-left:11%;\"><b>_BSD_SOURCE<\/b> (deprecated since glibc 2.20)<\/p>\n<p style=\"margin-left:22%;\">Defining this macro with any value causes header files to expose BSD-derived definitions.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">In glibc versions up to and including 2.18, defining this macro also causes BSD definitions to be preferred in some situations where standards conflict, unless one or more of <b>_SVID_SOURCE<\/b>, <b>_POSIX_SOURCE<\/b>, <b>_POSIX_C_SOURCE<\/b>, <b>_XOPEN_SOURCE<\/b>, <b>_XOPEN_SOURCE_EXTENDED<\/b>, or <b>_GNU_SOURCE<\/b> is defined, in which case BSD definitions are disfavored. Since glibc 2.19, <b>_BSD_SOURCE<\/b> no longer causes BSD definitions to be preferred in case of conflicts.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Since glibc 2.20, this macro is deprecated. It now has the same effect as defining <b>_DEFAULT_SOURCE<\/b>, but generates a compile-time warning (unless <b>_DEFAULT_SOURCE<\/b> is also defined). Use <b>_DEFAULT_SOURCE<\/b> instead. To allow code that requires <b>_BSD_SOURCE<\/b> in glibc 2.19 and earlier and <b>_DEFAULT_SOURCE<\/b> in glibc 2.20 and later to compile without warnings, define <i>both<\/i> <b>_BSD_SOURCE<\/b> and <b>_DEFAULT_SOURCE<\/b>.<\/p>\n<p style=\"margin-left:11%;\"><b>_SVID_SOURCE<\/b> (deprecated since glibc 2.20)<\/p>\n<p style=\"margin-left:22%;\">Defining this macro with any value causes header files to expose System V-derived definitions. (SVID == System V Interface Definition; see <b>standards<\/b>(7).)<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Since glibc 2.20, this macro is deprecated in the same fashion as <b>_BSD_SOURCE<\/b>.<\/p>\n<p style=\"margin-left:11%;\"><b>_DEFAULT_SOURCE<\/b> (since glibc 2.19)<\/p>\n<p style=\"margin-left:22%;\">This macro can be defined to ensure that the &#8220;default&#8221; definitions are provided even when the defaults would otherwise be disabled, as happens when individual macros are explicitly defined, or the compiler is invoked in one of its &#8220;standard&#8221; modes (e.g., <i>cc\u00a0\u2212std=c99<\/i>). Defining <b>_DEFAULT_SOURCE<\/b> without defining other individual macros or invoking the compiler in one of its &#8220;standard&#8221; modes has no effect.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">The &#8220;default&#8221; definitions comprise those required by POSIX.1-2008 and ISO C99, as well as various definitions originally derived from BSD and System V. On glibc 2.19 and earlier, these defaults were approximately equivalent to explicitly defining the following:<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">cc \u2212D_BSD_SOURCE \u2212D_SVID_SOURCE \u2212D_POSIX_C_SOURCE=200809<\/p>\n<p style=\"margin-left:11%;\"><b>_ATFILE_SOURCE<\/b> (since glibc 2.4)<\/p>\n<p style=\"margin-left:22%;\">Defining this macro with any value causes header files to expose declarations of a range of functions with the suffix &#8220;at&#8221;; see <b>openat<\/b>(2). Since glibc 2.10, this macro is also implicitly defined if <b>_POSIX_C_SOURCE<\/b> is defined with a value greater than or equal to 200809L.<\/p>\n<p style=\"margin-left:11%;\"><b>_GNU_SOURCE<\/b><\/p>\n<p style=\"margin-left:22%;\">Defining this macro (with any value) implicitly defines <b>_ATFILE_SOURCE<\/b>, <b>_LARGEFILE64_SOURCE<\/b>, <b>_ISOC99_SOURCE<\/b>, <b>_XOPEN_SOURCE_EXTENDED<\/b>, <b>_POSIX_SOURCE<\/b>, <b>_POSIX_C_SOURCE<\/b> with the value 200809L (200112L in glibc versions before 2.10; 199506L in glibc versions before 2.5; 199309L in glibc versions before 2.1) and <b>_XOPEN_SOURCE<\/b> with the value 700 (600 in glibc versions before 2.10; 500 in glibc versions before 2.2). In addition, various GNU-specific extensions are also exposed.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Since glibc 2.19, defining <b>_GNU_SOURCE<\/b> also has the effect of implicitly defining <b>_DEFAULT_SOURCE<\/b>. In glibc versions before 2.20, defining <b>_GNU_SOURCE<\/b> also had the effect of implicitly defining <b>_BSD_SOURCE<\/b> and <b>_SVID_SOURCE<\/b>.<\/p>\n<p style=\"margin-left:11%;\"><b>_REENTRANT<\/b><\/p>\n<p style=\"margin-left:22%;\">Historically, on various C libraries it was necessary to define this macro in all multithreaded code. (Some C libraries may still require this.) In glibc, this macro also exposed definitions of certain reentrant functions.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">However, glibc has been thread-safe by default for many years; since glibc 2.3, the only effect of defining <b>_REENTRANT<\/b> has been to enable one or two of the same declarations that are also enabled by defining <b>_POSIX_C_SOURCE<\/b> with a value of 199606L or greater.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>_REENTRANT<\/b> is now obsolete. In glibc 2.25 and later, defining <b>_REENTRANT<\/b> is equivalent to defining <b>_POSIX_C_SOURCE<\/b> with the value 199606L. If a higher POSIX conformance level is selected by any other means (such as <b>_POSIX_C_SOURCE<\/b> itself, <b>_XOPEN_SOURCE<\/b>, <b>_DEFAULT_SOURCE<\/b>, or <b>_GNU_SOURCE<\/b>), then defining <b>_REENTRANT<\/b> has no effect.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">This macro is automatically defined if one compiles with <i>cc\u00a0\u2212pthread<\/i>.<\/p>\n<p style=\"margin-left:11%;\"><b>_THREAD_SAFE<\/b><\/p>\n<p style=\"margin-left:22%;\">Synonym for the (deprecated) <b>_REENTRANT<\/b>, provided for compatibility with some other implementations.<\/p>\n<p style=\"margin-left:11%;\"><b>_FORTIFY_SOURCE<\/b> (since glibc 2.3.4)<\/p>\n<p style=\"margin-left:22%;\">Defining this macro causes some lightweight checks to be performed to detect some buffer overflow errors when employing various string and memory manipulation functions (for example, <b>memcpy<\/b>(3), <b>memset<\/b>(3), <b>stpcpy<\/b>(3), <b>strcpy<\/b>(3), <b>strncpy<\/b>(3), <b>strcat<\/b>(3), <b>strncat<\/b>(3), <b>sprintf<\/b>(3), <b>snprintf<\/b>(3), <b>vsprintf<\/b>(3), <b>vsnprintf<\/b>(3), <b>gets<\/b>(3), and wide character variants thereof). For some functions, argument consistency is checked; for example, a check is made that <b>open<\/b>(2) has been supplied with a <i>mode<\/i> argument when the specified flags include <b>O_CREAT<\/b>. Not all problems are detected, just some common cases.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">If <b>_FORTIFY_SOURCE<\/b> is set to 1, with compiler optimization level 1 (<i>gcc\u00a0\u2212O1<\/i>) and above, checks that shouldn\u2019t change the behavior of conforming programs are performed. With <b>_FORTIFY_SOURCE<\/b> set to 2, some more checking is added, but some conforming programs might fail.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Some of the checks can be performed at compile time (via macros logic implemented in header files), and result in compiler warnings; other checks take place at run time, and result in a run-time error if the check fails.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Use of this macro requires compiler support, available with <b>gcc<\/b>(1) since version 4.0.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Default definitions, implicit definitions, and combining definitions<\/b> <br \/> If no feature test macros are explicitly defined, then the following feature test macros are defined by default: <b>_BSD_SOURCE<\/b> (in glibc 2.19 and earlier), <b>_SVID_SOURCE<\/b> (in glibc 2.19 and earlier), <b>_DEFAULT_SOURCE<\/b> (since glibc 2.19), <b>_POSIX_SOURCE<\/b>, and <b>_POSIX_C_SOURCE<\/b>=200809L (200112L in glibc versions before 2.10; 199506L in glibc versions before 2.4; 199309L in glibc versions before 2.1).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If any of <b>__STRICT_ANSI__<\/b>, <b>_ISOC99_SOURCE<\/b>, <b>_ISOC11_SOURCE<\/b> (since glibc 2.18), <b>_POSIX_SOURCE<\/b>, <b>_POSIX_C_SOURCE<\/b>, <b>_XOPEN_SOURCE<\/b>, <b>_XOPEN_SOURCE_EXTENDED<\/b> (in glibc 2.11 and earlier), <b>_BSD_SOURCE<\/b> (in glibc 2.19 and earlier), or <b>_SVID_SOURCE<\/b> (in glibc 2.19 and earlier) is explicitly defined, then <b>_BSD_SOURCE<\/b>, <b>_SVID_SOURCE<\/b>, and <b>_DEFAULT_SOURCE<\/b> are not defined by default.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <b>_POSIX_SOURCE<\/b> and <b>_POSIX_C_SOURCE<\/b> are not explicitly defined, and either <b>__STRICT_ANSI__<\/b> is not defined or <b>_XOPEN_SOURCE<\/b> is defined with a value of 500 or more, then<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"85%\">\n<p><b>_POSIX_SOURCE<\/b> is defined with the value 1; and<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"1%\">\n<p>*<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"85%\">\n<p><b>_POSIX_C_SOURCE<\/b> is defined with one of the following values:<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:15%;\">\u2022<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"15%\"><\/td>\n<td width=\"2%\"><\/td>\n<td width=\"3%\"><\/td>\n<td width=\"80%\">\n<p style=\"margin-top: 1em\">2, if <b>_XOPEN_SOURCE<\/b> is defined with a value less than 500;<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"15%\"><\/td>\n<td width=\"2%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"80%\">\n<p>199506L, if <b>_XOPEN_SOURCE<\/b> is defined with a value greater than or equal to 500 and less than 600; or<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"15%\"><\/td>\n<td width=\"2%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"80%\">\n<p>(since glibc 2.4) 200112L, if <b>_XOPEN_SOURCE<\/b> is defined with a value greater than or equal to 600 and less than 700.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"15%\"><\/td>\n<td width=\"2%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"80%\">\n<p>(Since glibc 2.10) 200809L, if <b>_XOPEN_SOURCE<\/b> is defined with a value greater than or equal to 700.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"15%\"><\/td>\n<td width=\"2%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"80%\">\n<p>Older versions of glibc do not know about the values 200112L and 200809L for <b>_POSIX_C_SOURCE<\/b>, and the setting of this macro will depend on the glibc version.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"15%\"><\/td>\n<td width=\"2%\">\n<p>\u2022<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"80%\">\n<p>If <b>_XOPEN_SOURCE<\/b> is undefined, then the setting of <b>_POSIX_C_SOURCE<\/b> depends on the glibc version: 199506L, in glibc versions before 2.4; 200112L, in glibc 2.4 to 2.9; and 200809L, since glibc 2.10.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">Multiple macros can be defined; the results are additive.<\/p>\n<h2>CONFORMING TO <a name=\"CONFORMING TO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">POSIX.1 specifies <b>_POSIX_C_SOURCE<\/b>, <b>_POSIX_SOURCE<\/b>, and <b>_XOPEN_SOURCE<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>_XOPEN_SOURCE_EXTENDED<\/b> was specified by XPG4v2 (aka SUSv1), but is not present in SUSv2 and later. <b>_FILE_OFFSET_BITS<\/b> is not specified by any standard, but is employed on some other implementations.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>_BSD_SOURCE<\/b>, <b>_SVID_SOURCE<\/b>, <b>_DEFAULT_SOURCE<\/b>, <b>_ATFILE_SOURCE<\/b>, <b>_GNU_SOURCE<\/b>, <b>_FORTIFY_SOURCE<\/b>, <b>_REENTRANT<\/b>, and <b>_THREAD_SAFE<\/b> are specific to Linux (glibc).<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i><features.h><\/i> is a Linux\/glibc-specific header file. Other systems have an analogous file, but typically with a different name. This header file is automatically included by other header files as required: it is not necessary to explicitly include it in order to employ feature test macros.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">According to which of the above feature test macros are defined, <i><features.h><\/i> internally defines various other macros that are checked by other glibc header files. These macros have names prefixed by two underscores (e.g., <b>__USE_MISC<\/b>). Programs should <i>never<\/i> define these macros directly: instead, the appropriate feature test macro(s) from the list above should be employed.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The program below can be used to explore how the various feature test macros are set depending on the glibc version and what feature test macros are explicitly set. The following shell session, on a system with glibc 2.10, shows some examples of what we would see:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">$ <b>cc ftm.c<\/b> <br \/> $ <b>.\/a.out<\/b> <br \/> _POSIX_SOURCE defined <br \/> _POSIX_C_SOURCE defined: 200809L <br \/> _BSD_SOURCE defined <br \/> _SVID_SOURCE defined <br \/> _ATFILE_SOURCE defined <br \/> $ <b>cc \u2212D_XOPEN_SOURCE=500 ftm.c<\/b> <br \/> $ <b>.\/a.out<\/b> <br \/> _POSIX_SOURCE defined <br \/> _POSIX_C_SOURCE defined: 199506L <br \/> _XOPEN_SOURCE defined: 500 <br \/> $ <b>cc \u2212D_GNU_SOURCE ftm.c<\/b> <br \/> $ <b>.\/a.out<\/b> <br \/> _POSIX_SOURCE defined <br \/> _POSIX_C_SOURCE defined: 200809L <br \/> _ISOC99_SOURCE defined <br \/> _XOPEN_SOURCE defined: 700 <br \/> _XOPEN_SOURCE_EXTENDED defined <br \/> _LARGEFILE64_SOURCE defined <br \/> _BSD_SOURCE defined <br \/> _SVID_SOURCE defined <br \/> _ATFILE_SOURCE defined <br \/> _GNU_SOURCE defined<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Program source<\/b> <br \/> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var ftm.c *\/<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <stdint.h> <br \/> #include <stdio.h> <br \/> #include <unistd.h> <br \/> #include <stdlib.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int <br \/> main(int argc, char *argv[]) <br \/> { <br \/> #ifdef _POSIX_SOURCE <br \/> printf(&#8220;_POSIX_SOURCE definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _POSIX_C_SOURCE <br \/> printf(&#8220;_POSIX_C_SOURCE defined: %jdLn&#8221;, <br \/> (intmax_t) _POSIX_C_SOURCE); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _ISOC99_SOURCE <br \/> printf(&#8220;_ISOC99_SOURCE definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _ISOC11_SOURCE <br \/> printf(&#8220;_ISOC11_SOURCE definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _XOPEN_SOURCE <br \/> printf(&#8220;_XOPEN_SOURCE defined: %dn&#8221;, _XOPEN_SOURCE); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _XOPEN_SOURCE_EXTENDED <br \/> printf(&#8220;_XOPEN_SOURCE_EXTENDED definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _LARGEFILE64_SOURCE <br \/> printf(&#8220;_LARGEFILE64_SOURCE definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _FILE_OFFSET_BITS <br \/> printf(&#8220;_FILE_OFFSET_BITS defined: %dn&#8221;, _FILE_OFFSET_BITS); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _BSD_SOURCE <br \/> printf(&#8220;_BSD_SOURCE definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _SVID_SOURCE <br \/> printf(&#8220;_SVID_SOURCE definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _DEFAULT_SOURCE <br \/> printf(&#8220;_DEFAULT_SOURCE definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _ATFILE_SOURCE <br \/> printf(&#8220;_ATFILE_SOURCE definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _GNU_SOURCE <br \/> printf(&#8220;_GNU_SOURCE definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _REENTRANT <br \/> printf(&#8220;_REENTRANT definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _THREAD_SAFE <br \/> printf(&#8220;_THREAD_SAFE definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#ifdef _FORTIFY_SOURCE <br \/> printf(&#8220;_FORTIFY_SOURCE definedn&#8221;); <br \/> #endif<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">exit(EXIT_SUCCESS); <br \/> }<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>libc<\/b>(7), <b>standards<\/b>(7), <b>system_data_types<\/b>(7)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The section &#8220;Feature Test Macros&#8221; under <i>info libc<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>\/usr\/include\/features.h<\/i><\/p>\n<h2>COLOPHON <a name=\"COLOPHON\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This page is part of release 5.10 of the Linux <i>man-pages<\/i> project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https:\/\/www.kernel.org\/doc\/man\u2212pages\/.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  feature_test_macros \u2212 feature test macros <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[971],"tags":[973,1038,972],"class_list":["post-3946","post","type-post","status-publish","format-standard","hentry","category-7-miscelanea","tag-973","tag-feature_test_macros","tag-man7"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=3946"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3946\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=3946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=3946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=3946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}