The scope and Storage Class of user identifiers in C Language (4 ).

Source: Internet
Author: User

The scope and Storage Class of user identifiers in C Language (4 ).
4. Storage Classification of functions

All functions are external, because it is not allowed to define another function within the function. However, when defining a function, you can use the extern or static specifier.

4.1 Use extern to describe the function

When defining a function, if the specifier extern is added before the type returned by the function, this function is called an "external" function. The extern description can be omitted. General functions are implicitly described as extern. Therefore, all the previously defined functions belong to external functions.

External functions can be called by functions in other compilation units. Generally, when a function call statement is not in the same compilation unit as the called function, and the return value of the function is not an integer, use extern to describe the called function in the description section of the function where the call statement is located.

4.2 use static to describe functions

When defining a function, if the descriptive character static is added before the type returned by the function, the function is called a "static" function.

The characteristics of a static function are as follows: only other functions in the current compilation unit call it, and functions in other compilation units are not allowed to call it. In this sense, static functions can also be called "internal functions" (internal functions in this file ). Using static functions can avoid confusion caused by different compilation units because of the same name of the function. If a static function is forcibly called, an error message is generated.

Related Article

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.