zoukankan      html  css  js  c++  java
  • Internal Linkage和External Linkage

    Linkage
    To understand the behavior of C and C++ programs, you need to know about linkage. In an executing program, an identifier is represented by storage in memory that holds a variable or a compiled function body. Linkage describes this storage as it is seen by the linker. There are two types of linkage: internal linkage and external linkage.


    Internal linkage means that storage is created to represent the identifier only for the file being compiled. Other files may use the same identifier name with internal linkage, or for a global variable, and no conflicts will be found by the linker – separate storage is created for each identifier.Internal linkage is specified by the keyword static in C and C++.


    External linkage means that a single piece of storage is created to represent the identifier for all files being compiled. The storage is created once, and the linker must resolve all other references to that storage. Global variables and function names have external linkage. These are accessed from other files by declaring them with the keyword extern. Variables defined outside all functions (with the exception of const in C++) and function definitions default to external linkage. You can specifically force them to have internal linkage using the static keyword. You can explicitly state that an identifier has external linkage by defining it with the extern keyword. Defining a variable or function with extern is not necessary in C, but it is sometimes necessary for const in C++.


    Automatic (local) variables exist only temporarily, on the stack, while a function is being called. The linker doesn’t know about automatic variables, and so these have no linkage.

  • 相关阅读:
    Swift和OC混编
    Excel数据导入___你hold住么(一)
    Cocos2d-x 3.0多线程异步资源载入
    FPGA实现网络通信时的网络字节序问题
    easyui datagrid 动态加入、移除editor
    struts.xml中出现extends undefined package struts-default解决的方法
    Maven入门
    后面需要继续完善的地方
    CentOS6.9 安装OpenResty
    数据库异步写入功能概要设计
  • 原文地址:https://www.cnblogs.com/xiongjiaji/p/2476507.html
Copyright © 2011-2022 走看看