Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting a warning "[-Wimplicit-int]"

Getting an error saying

calculator.c:11:9: warning: type of ‘num1’ defaults to ‘int’ [-Wimplicit-int]
11 | int addition(num1, num2)"

The code will still run but wondering why this comes up?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include <stdio.h>

int main()
{
    int num1;
    int num2;

    int addition(num1, num2)
    {
        return num1+num2;
    }

    int subtraction(num1, num2)
    {
        return num1-num2;
    }

    int multiply(num1, num2)
    {
        return num1*num2;   
    }

    float devide(num1, num2)
    {
        return num1/num2;
    }

    printf("Still works");

}

>Solution :

First, do not put your functions inside main.
Each function should be standalone:

#include <stdio.h>

int addition(num1, num2)   // Function BEFORE main, not inside main
{
    return num1+num2;  
}


int main()
{
    int num1;
    int num2;
    ....
}

Secondly, when declaring your functions, give a type to each parameter:

int addition(int num1, int num2)   // Declared each parameter as "int"
{
    return num1+num2;  
}

Finally, for long term code-usability, be consistent and correct with names.

// You named the first two functions addition and subtraction
// so this one should be "multiplication", not "multiply"!
// A sudden change in naming convention means poor design!
int multiply(num1, num2)


// The proper spelling of the operation is "divide" or "division"
// You will make other programmers jobs extremely difficult
// if they cannot tell what function this is, because of a misspelling.
float devide(num1, num2)

Putting all these changes together:

#include <stdio.h>


int addition(int num1, int num2)
{
    return num1+num2;
}

int subtraction(int num1, int num2)
{
    return num1-num2;
}

int multiplication(int num1, int num2)
{
    return num1*num2;   
}

float division(int num1, int num2)
{
    return (float)num1/num2;
}

int main()
{
    int num1;
    int num2;

    printf("Still works");
    return 0;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading