What is external linkage and internal linkage?

前端 未结 9 1384
情深已故
情深已故 2020-11-22 00:10

I want to understand the external linkage and internal linkage and their difference.

I also want to know the meaning of

const va

9条回答
  •  自闭症患者
    2020-11-22 00:28

    I think Internal and External Linkage in C++ gives a clear and concise explanation:

    A translation unit refers to an implementation (.c/.cpp) file and all header (.h/.hpp) files it includes. If an object or function inside such a translation unit has internal linkage, then that specific symbol is only visible to the linker within that translation unit. If an object or function has external linkage, the linker can also see it when processing other translation units. The static keyword, when used in the global namespace, forces a symbol to have internal linkage. The extern keyword results in a symbol having external linkage.

    The compiler defaults the linkage of symbols such that:

    Non-const global variables have external linkage by default
    Const global variables have internal linkage by default
    Functions have external linkage by default

提交回复
热议问题