How does an extern “C” declaration work?

后端 未结 9 763
礼貌的吻别
礼貌的吻别 2020-12-02 14:33

I\'m taking a programming languages course and we\'re talking about the extern \"C\" declaration.

How does this declaration work at a deeper level othe

9条回答
  •  一生所求
    2020-12-02 15:10

    It should be noted that extern "C" also modifies the types of functions. It does not only modify things on lower levels:

    extern "C" typedef void (*function_ptr_t)();
    
    void foo();
    
    int main() { function_ptr_t fptr = &foo; } // error!
    

    The type of &foo does not equal the type that the typedef designates (although the code is accepted by some, but not all compilers).

提交回复
热议问题