How does an extern “C” declaration work?

后端 未结 9 762
礼貌的吻别
礼貌的吻别 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:07

    extern "C" denotes that the enclosed code uses C-style linking and name mangling. C++ uses a more complex name mangling format. Here's an example:

    http://en.wikipedia.org/wiki/Name_mangling

    int example(int alpha, char beta);
    

    in C: _example

    in C++: __Z7exampleic

    Update: As GManNickG notes in the comments, the pattern of name mangling is compiler dependent.

提交回复
热议问题