添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more

It allows you to use functions that are not part of the standard C library but are part of the POSIX.1 (IEEE Standard 1003.1) standard. Using the macros described in feature_test_macros allows you to control the definitions exposed by the system header files.

As far as I know _POSIX_SOURCE is obsolete and you should use _POSIX_C_SOURCE instead.

For example, if you want to use strndup , you have to use

#define _POSIX_C_SOURCE 200809L

See also

  • 1.3.4 Feature Test Macros
  • 5.12 Posix Variants
  • man 7 feature_test_macros
  • If you are working on Linux with GCC, then by default it works in -std=gnu11 or -std=gnu90 mode, and the POSIX (and some other) sets of symbols are made visible without you needing to set _XOPEN_SOURCE or _POSIX_C_SOURCE or other similar macros. If you use -std=c11 or -std=c99 or (perish the thought) -std=c90, then POSIX and GNU symbols are not available by default; you have to define _XOPEN_SOURCE or _POSIX_C_SOURCE to see the POSIX symbols. – Jonathan Leffler Jan 19 '18 at 4:08

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.