C/C + + internal functions and external functions

Source: Internet
Author: User

Functions are global in nature, because a function is called by another function, or it can be specified that the function cannot be called by another file. The functions are distinguished from internal and external functions, depending on whether they can be called by other source files.


intrinsic function: (also called static function)

Can only be called by other functions in this file. Define the intrinsic function format as follows:

Static type identifier function name (formal parameter list)

such as: static int fun (int x,int y)

Using intrinsic functions, you can restrict the scope of a function to the file in which it resides, and have internal functions of the same name in different files. So different people can write different functions, without worrying about whether the function will have the same name as a function in other files, and usually put functions and external variables that can only be used by the same file in the same file, preceded by static to localize them, other files cannot be referenced.


External functions:

1. When defining a function, add the keyword extern at the leftmost end to indicate that the function is an external function (in C, omit extern, which is implied as an external function)

extern int fun (int x,int y)


2. In the file that needs to call this function, use extern to declare the function as an external function defined in another file.


A function prototype can extend the scope of a function beyond the file that defines the function (without using extern), as long as the function prototype of the function is included in each file that uses the function. Function prototype notifies the compilation system that the function is defined later in this file, or in another file.


--From the ancient rectification version C programming.


C/C + + internal functions and external functions

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.