I'm getting this warning when I'm trying to compare RGB components of two UIColors
In .h file, I declared this
-(int) ColorDiff:(UIColor *) color1 :(UIColor *)color2;
In .m file
- (int) ColorDiff:(UIColor *) color1 :(UIColor *)color2{
... //get RGB components from color1& color2
// compute differences of red, green, and blue values
CGFloat red = red1 - red2;
CGFloat green = green1 - green2;
CGFloat blue = blue1 - blue2;
// return sum of squared differences
return (abs(red) + abs(green) + abs(blue));
}
And then in same .m file, I compare 2 UIColors like this
int d= ColorDiff(C1,C2);// I got the warning right here.
I did research and people say I must include the header file. I did this but didn't help in my case. Why am I getting this error?
Code in header files should NOT call functions. 9/30/2020. NKurzman. First you have the Option to tell the compiler to use C90 ode. implicit declaration of function means you do not have Prototypes for your functions.
Such an 'implicit declaration' is really an oversight or error by the programmer, because the C compiler needs to know about the types of the parameters and return value to correctly allocate them on the stack.
It's because you defined your function as a instance method, not a function. There are two solutions.
One of which is this to change your method declaration to this:
int ColorDiff(UIColor *color1, UIColor *color2) { // colorDiff's implementation }
Or, you can change your call to this:
int d = [self ColorDiff:C1:C2];
The declaration in your .h file doesn't match your implementation in your .m file.
if the implementation of your method in your .m looks like this:
- (int) ColorDiffBetweenColorOne:(UIColor *) color1 AndColorTwo:(UIColor *)color2
{
... //get RGB components from color1& color2
// compute differences of red, green, and blue values
CGFloat red = red1 - red2;
CGFloat green = green1 - green2;
CGFloat blue = blue1 - blue2;
// return sum of squared differences
return (abs(red) + abs(green) + abs(blue));
}
than you should declare it like this in .h:
- (int) ColorDiffBetweenColorOne:(UIColor *) color1 AndColorTwo:(UIColor *)color2;
and to call it from that same .m file, use:
int d = [self ColorDiffBetweenColorOne:C1 AndColorTwo:C2];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With