Question:
"Conflicting types for function" C program issue?
ShadoW
2013-12-31 09:37:49 UTC
I created a simple function that is meant to calculate the remainder. This is the function prototype:

int remainder (int x1, int x2);

And this is the implementation:

int remainder (int x1, int x2){
return(x1%x2);
}

And this is where the function call occurs:

int x1, x2, prod_rem;

printf ("\nEnter the first number followed by the second number:\n");
scanf ("%d%d", &x1, &x2);
prod_rem = remainder(x1, x2);
printf ("\nResult is %d", prod_rem);

The program is pretty big -- a whole calculator, around 350 lines or so... so the whole code is not needed I suppose.

When I try to compile and run it gives me the error:

"Conflicting types for 'remainder'"

I don't know where the conflict is happening, it looks perfectly compatible to me.

Is there something wrong with my code or is this a common issue or what exactly? How to fix it?

Thanks in advance for any answers.
Five answers:
Chuck
2013-12-31 17:37:34 UTC
Wow, what a bunch of bad answers. Guys, if you don't know the answer to a question, why bother trying to answer?



"remainder" is a builtin function (usually a macro) for C99-compliant compilers. Either rename your function to not conflict with the token "remainder" or use the appropriate compile-time flag to disable it. (Or just use the builtin without trying to redefine it).



For gcc, for example, you could compile with "-fno-builtin-remainder" or simply "-ansi" (the latter turns off all C99 builtins, including remainder). There are several other ways, all depending on exactly what you want to disable and/or how you want to change compilation behavior or rules. As always, read the fine manual for your specific compiler.



Programmatically, the function you have written is completely superfluous; why not just use the mod/% operator instead of the function call altogether? Or just the builtin? That's another discussion, though.
anonymous
2016-12-12 18:38:39 UTC
Types Of Function In C
James Bond
2013-12-31 09:42:39 UTC
May be the code which you have shown is correct. Error is some where else.

Meaning of this error is that you are not sending correct type of arguments to remainder function some where in your program.

Do check. The above given call is valid according to given function definition/prototype.

Somewhere you are calling with other type arguments instead of integers
noob
2013-12-31 11:01:40 UTC
Sorry, I did not notice that you prototyped and thought that was the reason.



Anyways, search for the function name in the program and see if you accidentally prototyped it a second time.
Chrisgotter
2013-12-31 11:48:12 UTC
have you named any other variables 'remainder'?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...