Does extern “C” have any effect in C?

后端 未结 3 1950
既然无缘
既然无缘 2021-02-13 10:03

I just got some C code that uses extern \"C\" to declare external functions like this:

extern \"C\" void func();

Is this valid C? I\'m getting

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-13 10:51

    this is a C++ notation to tell the compiler/linker to use C calling standards.

    Usually that line is wrapped in an pre-processor statement.

    #ifdef __cplusplus
    extern "C" {
    #endif
    
    // stuff
    
    #ifdef __cplusplus
    }
    #endif
    

提交回复
热议问题