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.

  • 相关阅读:
    grub menu from pygrub
    Unix调试的瑞士军刀:lsof
    Quantum & r2q
    Linux TC基于CBQ队列的流量管理范例
    hfsc
    用bash做个tcp客户端
    [转]HFSC Scheduling with Linux
    [转]如何判断 Linux 是否运行在虚拟机上
    TSO
    使用VS2008进行WEB负载测试
  • 原文地址:https://www.cnblogs.com/xiongjiaji/p/2476507.html
Copyright © 2011-2022 走看看