# man > feature_test_macros(7)

---
type: CommandReference
command: feature_test_macros
mode: man
section: 7
source: man-pages
---

## Quick Reference

- `-D_GNU_SOURCE` — expose GNU/Linux-specific features and enable POSIX, C99, XPG, etc.
- `-D_POSIX_C_SOURCE=200809L` — expose POSIX.1-2008 base definitions
- `-D_XOPEN_SOURCE=700` — expose SUSv4 (POSIX.1-2008 + XSI)
- `-D_DEFAULT_SOURCE` — ensure default definitions are provided when other macros are defined
- `-D_BSD_SOURCE` (deprecated) — expose BSD definitions (use `_DEFAULT_SOURCE` instead)
- `-D_FILE_OFFSET_BITS=64` — use 64-bit file offsets on 32-bit systems
- `-D_FORTIFY_SOURCE=2` — enable lightweight buffer overflow checks (requires compiler optimization)
- `-std=c99` instead of `-D_ISOC99_SOURCE` — same effect
- `-pthread` automatically defines `_REENTRANT`

## Name

feature_test_macros — control the definitions exposed by system header files

## Synopsis

Feature test macros must be defined **before including any header files**, either via `-D` on the compiler command line or by `#define` in source code.  
Example:

shell
cc -D_GNU_SOURCE program.c
or in source:

c
#define _GNU_SOURCE
#include <stdio.h>
## Options

### Modern POSIX / XPG macros

- `_POSIX_C_SOURCE` — values: 1 (POSIX.1-1990), 2 (POSIX.2-1992), 199309L (POSIX.1b real-time), 199506L (POSIX.1c threads), 200112L (POSIX.1-2001), 200809L (POSIX.1-2008). Also enables C95/C99 when ≥200112L.
- `_XOPEN_SOURCE` — values: <500 (XPG4), ≥500 (SUSv2/UNIX 98), ≥600 (SUSv3/UNIX 03), ≥700 (SUSv4). Implicitly defines `_POSIX_SOURCE` and `_POSIX_C_SOURCE` accordingly.
- `_XOPEN_SOURCE_EXTENDED` (obsolete) — expose XPG4v2 (SUSv1) extensions. Same effect as `_XOPEN_SOURCE >= 500`.

### C standard macros

- `__STRICT_ANSI__` — defined by `gcc -std=c99` or `-ansi`. Exposes only ISO C.
- `_ISOC99_SOURCE` — expose C99 declarations (also enables C95). Equivalent to `-std=c99`.
- `_ISOC11_SOURCE` — expose C11 declarations (also enables C99/C95). Equivalent to `-std=c11`.

### Large file support

- `_LARGEFILE64_SOURCE` — expose 64-bit types and functions (e.g., `off64_t`, `lseek64`). New programs should use `_FILE_OFFSET_BITS=64` instead.
- `_LARGEFILE_SOURCE` — expose `fseeko()` and `ftello()`. Implicit when `_XOPEN_SOURCE >= 500`.
- `_FILE_OFFSET_BITS=64` — on 32-bit systems, redirect 32-bit file I/O calls to 64-bit counterparts. No effect on 64-bit systems.

### BSD / System V / default macros

- `_BSD_SOURCE` (deprecated since glibc 2.20) — expose BSD definitions. Now same as `_DEFAULT_SOURCE` but generates a warning.
- `_SVID_SOURCE` (deprecated since glibc 2.20) — expose System V definitions. Same deprecation as `_BSD_SOURCE`.
- `_DEFAULT_SOURCE` (since glibc 2.19) — ensures default definitions (POSIX.1-2008, C99, BSD, SysV) are provided even when other macros are defined.

### Other macros

- `_ATFILE_SOURCE` — expose `*at()` functions (e.g., `openat()`). Implicit when `_POSIX_C_SOURCE >= 200809L`.
- `_GNU_SOURCE` — defines `_ATFILE_SOURCE`, `_LARGEFILE64_SOURCE`, `_ISOC99_SOURCE`, `_XOPEN_SOURCE_EXTENDED`, `_POSIX_SOURCE`, `_POSIX_C_SOURCE=200809L`, `_XOPEN_SOURCE=700`, and GNU extensions. Since glibc 2.19 also defines `_DEFAULT_SOURCE`.
- `_REENTRANT` (obsolete) — historically for multithreaded code. Since glibc 2.25 equivalent to `_POSIX_C_SOURCE=199506L`. Automatically defined by `-pthread`.
- `_THREAD_SAFE` (obsolete) — synonym for `_REENTRANT`.
- `_FORTIFY_SOURCE` (since glibc 2.3.4) — set to 1 or 2 to enable compile-time and run-time checks for buffer overflows (requires `gcc -O1` or higher). Level 2 may break some conforming programs.

### Default definitions

When no feature test macros are explicitly defined, the following are defined by default:

- `_BSD_SOURCE` (glibc ≤2.19)
- `_SVID_SOURCE` (glibc ≤2.19)
- `_DEFAULT_SOURCE` (glibc ≥2.19)
- `_POSIX_SOURCE`
- `_POSIX_C_SOURCE=200809L` (200112L in glibc <2.10; 199506L in glibc <2.4; 199309L in glibc <2.1)

If any of `__STRICT_ANSI__`, `_ISOC99_SOURCE`, `_ISOC11_SOURCE`, `_POSIX_SOURCE`, `_POSIX_C_SOURCE`, `_XOPEN_SOURCE`, `_XOPEN_SOURCE_EXTENDED`, `_BSD_SOURCE`, or `_SVID_SOURCE` is explicitly defined, then `_BSD_SOURCE`, `_SVID_SOURCE`, and `_DEFAULT_SOURCE` are **not** defined by default.

## Examples

### Exploring active macros with `ftm.c`

c
/* ftm.c */
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
#ifdef _POSIX_SOURCE
    printf("_POSIX_SOURCE defined\n");
#endif
#ifdef _POSIX_C_SOURCE
    printf("_POSIX_C_SOURCE defined: %jdL\n", (intmax_t) _POSIX_C_SOURCE);
#endif
#ifdef _ISOC99_SOURCE
    printf("_ISOC99_SOURCE defined\n");
#endif
#ifdef _ISOC11_SOURCE
    printf("_ISOC11_SOURCE defined\n");
#endif
#ifdef _XOPEN_SOURCE
    printf("_XOPEN_SOURCE defined: %d\n", _XOPEN_SOURCE);
#endif
#ifdef _XOPEN_SOURCE_EXTENDED
    printf("_XOPEN_SOURCE_EXTENDED defined\n");
#endif
#ifdef _LARGEFILE64_SOURCE
    printf("_LARGEFILE64_SOURCE defined\n");
#endif
#ifdef _FILE_OFFSET_BITS
    printf("_FILE_OFFSET_BITS defined: %d\n", _FILE_OFFSET_BITS);
#endif
#ifdef _BSD_SOURCE
    printf("_BSD_SOURCE defined\n");
#endif
#ifdef _SVID_SOURCE
    printf("_SVID_SOURCE defined\n");
#endif
#ifdef _DEFAULT_SOURCE
    printf("_DEFAULT_SOURCE defined\n");
#endif
#ifdef _ATFILE_SOURCE
    printf("_ATFILE_SOURCE defined\n");
#endif
#ifdef _GNU_SOURCE
    printf("_GNU_SOURCE defined\n");
#endif
#ifdef _REENTRANT
    printf("_REENTRANT defined\n");
#endif
#ifdef _THREAD_SAFE
    printf("_THREAD_SAFE defined\n");
#endif
#ifdef _FORTIFY_SOURCE
    printf("_FORTIFY_SOURCE defined\n");
#endif
    exit(EXIT_SUCCESS);
}
### Shell session (glibc 2.10)

shell
$ cc ftm.c
$ ./a.out
_POSIX_SOURCE defined
_POSIX_C_SOURCE defined: 200809L
_BSD_SOURCE defined
_SVID_SOURCE defined
_ATFILE_SOURCE defined
$ cc -D_XOPEN_SOURCE=500 ftm.c
$ ./a.out
_POSIX_SOURCE defined
_POSIX_C_SOURCE defined: 199506L
_XOPEN_SOURCE defined: 500
$ cc -D_GNU_SOURCE ftm.c
$ ./a.out
_POSIX_SOURCE defined
_POSIX_C_SOURCE defined: 200809L
_ISOC99_SOURCE defined
_XOPEN_SOURCE defined: 700
_XOPEN_SOURCE_EXTENDED defined
_LARGEFILE64_SOURCE defined
_BSD_SOURCE defined
_SVID_SOURCE defined
_ATFILE_SOURCE defined
_GNU_SOURCE defined
## See Also

- [**libc**(7)](http://localhost/phpMan.php/man/libc/7/markdown)
- [**standards**(7)](http://localhost/phpMan.php/man/standards/7/markdown)
- [**system_data_types**(7)](http://localhost/phpMan.php/man/system_data_types/7/markdown)
- `info libc` (section "Feature Test Macros")
- `/usr/include/features.h`
