Differences between function prototypes and function definitions

Source: Internet
Author: User

As the saying goes: "A good memory is worse than a bad keyboard ". I recently read 《C ++ProgramDesign tutorial. I have some insights on the differences between the function prototype and the function definition in the function call. I will record it and study it later.

 

When defining a function, the program pushes the parameters to be passed into the stack. The specific parameter sequence is related to the compiler. Then Call The address of the called function. Sometimes the program passes compilation during compilation, and the connection becomes faulty, prompting that the function body cannot be found, Vc6.0 Tip: Unresolved externals This is sometimes caused by inconsistent function definitions with function declarations. Why can't I connect through compilation? This involves the compilation process. During compilation, it usually checks whether the syntax is correct and whether the function is called in accordance with the call specifications. How can we ensure the call specifications? Is through the function prototype. The compiler searches for all function prototypes to see if there are any declarations that match the function call form. If yes, the compiler compiles the statements. As for the specific content of the function definition, the compiler only performs regular syntax checks. It is estimated that the compilation is carried out in function segments and is finally connected. Therefore, an error will be reported during the connection, indicating that the connection cannot be found.

 

Another function prototype is different in definition. If you want to add the default parameters of a function, you must add them to the function declaration. Instead, you cannot add them to the Function Definition and add them to the function declaration, the compiler will push the parameters into the stack in advance. If the parameter is placed in the definition, compilation will fail, if both the prototype and definition have default parameters, the default parameters are repeatedly defined ~~~ It may be that pressure is not allowed. 2 next stack), only default parameters are defined, when a function is called without parameters, because the parameters called during compilation are checked by the function prototype, compilation is not supported.

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.