zoukankan      html  css  js  c++  java
  • 【C】external/internal/static/register variable and function

     external(global)

     external variable is defined outside of functions. They are available to all the below functions and all of reference points to the same instance. 

     Unlike variable, functions are all external because C don't allow define function inside another. 

     If they are referred before it's defined or it's defined in different file, extern keyword should be used. Like:

    In file1:
        extern int sp;
        extern char var [];
    
        void pushvar(double f) {...};
        void pop(void) {...};
    
    In file2:
        int sp =0;
        char var[MAXNUM];
    

      

    internal(local)

    internal variable are also called automatic variable. They're defined in functions,  come to existence when the function is entered and disappear when left. 

    static

    static keyword could be applied to:

    1, external var. In this case, the scope of var is limited to the rest of the current complied file.Without external keyword, variable wlll be seen from the whole program.

    2, internal var. In this case, var is not destroyed after function exit. It could be used to save value between different times of function invoke.

    3, function. In this case , function scope is limited to the rest of the current compiled file, just like external var. 

    Register

    Register keyword imply that this variable is heavily used. Register keyword can only be applied to automatic variable.  

    PS: external and static var has to be intialized by constant expression while automatic and register var  has no such restiction. If absence of explicit initialization, external and static var is initialized to 0, automatic and register var have undefined values. 

  • 相关阅读:
    程序员修炼之道——从小工到专家 读书笔记
    Spring5 IOC原理
    2021下期末总结
    十年风雨,一个普通程序员的成长之路(五) 成长:得到与教训
    UmbracoXslDevelopmentTemplate CQ
    Asp.net中的数据绑定 CQ
    Building the DotNetNuke Module in Normal Asp.net Application CQ
    UmbracoDataTypeFirstGlance CQ
    Umbraco Home CQ
    UmbracoColor Picker–Demo CQ
  • 原文地址:https://www.cnblogs.com/dracohan/p/2937996.html
Copyright © 2011-2022 走看看