Do I need an extern “C” block to include standard POSIX C headers?

前端 未结 6 1833
一向
一向 2020-11-29 11:21

Do I need an extern \"C\" {} block to include standard C headers in a C++ program. Only consider standard C headers which do not have counterparts in C++.

6条回答
  •  Happy的楠姐
    2020-11-29 11:52

    Yes, you do. However, many systems (notably Linux) are already adding an extern "C" bracketing like you do. See (on Linux) files /usr/include/unistd.h /usr/include/features.h and the macro __BEGIN_DECLS defined in /usr/include/sys/cdefs.h and used in many Linux system include files.

    So on Linux, you usually can avoid your extern "C" but it does not harm (and, IMHO, improve readability in that case).

提交回复
热议问题