Question:
I wrote some C code, and an error keeps on coming up and I don't know what it means or how to fix it?
Huntsman
2010-04-03 23:48:05 UTC
I wrote a little bit of C code, spread among a main file, a secondary file and a header file. It is one that does simple calculations. The only thing is, when I compile it, it comes up with:

mare.c:8: error: redefinition of ‘subtraction’
mare.c:5: error: previous definition of ‘subtraction’ was here

Mare being the secondary file. The code for the secondary file is:

float division (float e, float f)
{ return (e / f); }

float subtraction (float a, float b)
{ return (a - b); }

float subtraction (float c, float d)
{ return (c - d); }

and the code for the header file is:

float subtraction (float a, float b)
float subtraction (float c, float d);
float division (float e, float f);
Four answers:
Black_Rabbit
2010-04-03 23:52:51 UTC
Remove the line:



float subtraction (float c, float d)

{ return (c - d); }



from your secondary file.



And the:



float subtraction (float c, float d);



from your header file.



You cannot declare multiple functions with the same name and arguments.
moviebuff
2010-04-03 23:54:58 UTC
The compiler is complaining because you are defining the function "subtraction" twice. Both function definitions take two float arguments and return a float, so to the compiler they are identical.



Why you are trying to do this, I don't know, but to fix it delete lines 8 and 9 in your mare.c file.
angel.....
2010-04-04 00:53:32 UTC
Place a semi colon after the float subtraction(float a, float b) n HEADER FILE!!!!

it will solve your problem
2010-04-03 23:51:51 UTC
There are two functions called "subtraction" that have the same signature. You can't do that.


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