What is external linkage and internal linkage?

前端 未结 9 1321
情深已故
情深已故 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:11

    In terms of 'C' (Because static keyword has different meaning between 'C' & 'C++')

    Lets talk about different scope in 'C'

    SCOPE: It is basically how long can I see something and how far.

    1. Local variable : Scope is only inside a function. It resides in the STACK area of RAM. Which means that every time a function gets called all the variables that are the part of that function, including function arguments are freshly created and are destroyed once the control goes out of the function. (Because the stack is flushed every time function returns)

    2. Static variable: Scope of this is for a file. It is accessible every where in the file
      in which it is declared. It resides in the DATA segment of RAM. Since this can only be accessed inside a file and hence INTERNAL linkage. Any
      other files cannot see this variable. In fact STATIC keyword is the only way in which we can introduce some level of data or function
      hiding in 'C'

    3. Global variable: Scope of this is for an entire application. It is accessible form every where of the application. Global variables also resides in DATA segment Since it can be accessed every where in the application and hence EXTERNAL Linkage

    By default all functions are global. In case, if you need to hide some functions in a file from outside, you can prefix the static keyword to the function. :-)

提交回复
热议问题