[c] Why this "Implicit declaration of function 'X'"?

I wrote a simple program to find the Sum, average, biggest and smallest number of 3 numbers. It lets the user to input three (integer) numbers and return the sum, average, max and min. It has no errors but a warning. Here is my source code:

main.c:

#include <stdio.h>

int main()
{
    int num1, num2, num3, sum, max, min, avg;

    printf("Enter Three \"Integer\" Numbers:");

    scanf("%i%i%i", &num1, &num2, &num3);

    sum = summation(&num1, &num2, &num3);
    avg = average(&sum);
    max = max_val(&num1, &num2, &num3);
    min = min_val(&num1, &num2, &num3);

    printf("Sum: %i Avg: %i MAX: %i MIN: %i", sum, avg, max, min);

    return 0;
}

int summation(int *n1, int *n2, int *n3)
{
    int s;
    s = *n1 + *n2 + *n3;

    return s;
}

int average(int *s)
{
    int a;
    a = *s / 3;

    return a;
}

int max_val(int *n1, int *n2, int *n3)
{
    int MAX;

    if (*n1 > *n2) MAX = *n1;
    else if (*n2 > *n3) MAX = *n2;
    else MAX = *n3;

    return MAX;
}

int min_val(int *n1, int *n2, int *n3)
{
    int MIN;

    if (*n1 < *n2) MIN = *n1;
    else if (*n2 < *n3) MIN = *n2;
    else MIN = *n3;

    return MIN;
}

I think there is no need to make a header file because all functions are in type of "int".

When I compile this

gcc main.c -o test

It says

main.c: In function 'main':
main.c:34:5: warning: implicit declaration of function 'summation' [-Wimplicit-function-declaration]

Why this warning? I can't find any wrong in that declaration. What's that?

This question is related to c function compiler-warnings

The answer is


summation and your other functions are defined after they're used in main, and so the compiler has made a guess about it's signature; in other words, an implicit declaration has been assumed.

You should declare the function before it's used and get rid of the warning. In the C99 specification, this is an error.

Either move the function bodies before main, or include method signatures before main, e.g.:

#include <stdio.h>

int summation(int *, int *, int *);

int main()
{
    // ...

Examples related to c

conflicting types for 'outchar' Can't compile C program on a Mac after upgrade to Mojave Program to find largest and second largest number in array Prime numbers between 1 to 100 in C Programming Language In c, in bool, true == 1 and false == 0? How I can print to stderr in C? Visual Studio Code includePath "error: assignment to expression with array type error" when I assign a struct field (C) Compiling an application for use in highly radioactive environments How can you print multiple variables inside a string using printf?

Examples related to function

$http.get(...).success is not a function Function to calculate R2 (R-squared) in R How to Call a Function inside a Render in React/Jsx How does Python return multiple values from a function? Default optional parameter in Swift function How to have multiple conditions for one if statement in python Uncaught TypeError: .indexOf is not a function Proper use of const for defining functions in JavaScript Run php function on button click includes() not working in all browsers

Examples related to compiler-warnings

Property getters and setters error C2220: warning treated as error - no 'object' file generated Objective-C implicit conversion loses integer precision 'NSUInteger' (aka 'unsigned long') to 'int' warning How do you disable the unused variable warnings coming out of gcc in 3rd party code I do not wish to edit? What is "android:allowBackup"? Why this "Implicit declaration of function 'X'"? How to compile without warnings being treated as errors? warning: implicit declaration of function Multi-character constant warnings What does "control reaches end of non-void function" mean?