Implicit declaration of C-language functions

Source: Internet
Author: User

C language variables must be declared after use, the function is no exception, this is not the same as js,php.

double function (void) { return100.0;}

Defines the first line of a function, declares the name of the function, the number of parameter types, the return value, which is called the function prototype,

Function prototypes can also be written separately without a function body

double function (void);

The compiler only knows the function's name when it encounters the function prototype, the number of parameter types returns the value, and the function call to know how to generate the instruction, so the function prototype must appear before the function call.

The following two pieces of code can get the correct results.

#include <stdio.h>double  function (void) {    return100.0;} int Main (void) {    printf ("%f", Function ());     return0;}

#include <stdio.h>int main (void) {    double function (void  );//function prototype    printf ("%f", Functions ())    ; return 0 ;} Double function (void) {    return100.0;}

If you remove the line that declares the function prototype. The function function is not declared when it is called in the main function, and the compiler considers the hermit to declare the INT function (void); The return value of a hermit declaration is int, because we don't pass arguments when we call function. So the compiler considers the argument type of this implicit function to be void.

The compiler then looks down and sees that the function is prototyped as a double function (void) and inconsistent with the previously implicitly declared type.

So error error:conflicting types for ' function ' previous implicit declaration of ' function ' is here

Implicit declaration of C-language 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.