Keyword parsing-static

Source: Internet
Author: User
In C, C ++, Java, and other languages Static As an English word, the basic meaning of this word is "static, fixed ". As the name suggests, this word is used to declare static objects.
1. C Language Static
C Language Program It can be viewed as composed of a series of external objects, which may be variables or functions. Internal variables refer to the function parameters and variables defined within the function. External variables are defined outside functions, so they can be used in many functions. Since the C language does not allow defining other functions in a function, the function itself can only be "external ".
Because of the C Language Code Objects are organized in units. In all source files of a source program, an external variable or function can only be defined once in a file. Extern Declaration to access it (the source file defining the external variable or function can also contain Extern Statement ).
While Static You can specify variables or functions for static storage. If you use Static Restrict external variables and functions to the remainder of the compiled source file. Pass Static Restrict external objects to hide external objects. Therefore, Static The specified variable or function does not conflict with the same name in other files in the same program. If you use Static If the internal variable is limited, the variable will have memory from the beginning of the program and will not be allocated and disappear as the function calls and exits. [1]

2. In C ++Static
Because c ++ is basically compatible with the features of C, C ++ inheritsStaticThe usage is called file static ). C ++ does not approve of static file. It has been replaced by an unnamed namespace.

 

reference:
[1] Brian W. kernighan, Dennis M. ritchie. (Xu Baowen, Li Zhi translated, you jinyuan School) C programming language (second edition · New Version ).
[2] C ++ primer Chinese edition: Stanley B. Lippman, Joseph Lajoie, Barbara E. Moo. (translated by Li shixian Jiang Aijun Li Xiaoyong Lin.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.