search

Home  >  Q&A  >  body text

c++ c混合编程问题?

c++里面用c语言的标准库的时候, 包含的c的标准头文件是不是自动extern "C"了.

比如 :

 #include <string.h>
 #include <stdio.h>
 
 是不是自动处理过了,可以用c的编译链接约定去找到并链接c标准库的函数?
高洛峰高洛峰2886 days ago739

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:20:01

    Yes, you can check the header file yourself and it is easy to find the following code

    #ifdef __cplusplus
    extern "C" {
    #endif
    ...
    ...
    #ifdef __cplusplus
    }
    #endif

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:20:01

    If it is a c standard library, it is best to import it like this:

    #include <cstring>
    #include <cstdio>
    

    This will help you deal with some problems such as function polymorphism

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:20:01

    Don’t worry about this, C++ is compatible with most C. As for linking dynamic libraries, the compiler has already done it for you

    reply
    0
  • Cancelreply