nineties
nineties

Reputation: 433

C: invalid operands to binary > (have ‘float’ and ‘float (*)(float **, long int, long int, short int *)’)

I wrote a very simple code to find max in an array. I cannot figure out what's wrong here...

float maxValue(float **ArrayIn, long length, long width, short* result_coor){
    int i,j;
    float maxvalue = ArrayIn[0][0];
    for(i=0;i<length;i++){
        for(j=0;j<width;j++){
            if((ArrayIn[i][j]>maxValue)==1){
                maxValue = ArrayIn[i][j];
                result_coor[0] = i;
                result_coor[1] = j;
            }
        }
    }
    return maxvalue;
}

I'm getting this error:

array_processing.c: In function ‘maxValue’:
array_processing.c:9:20: error: invalid operands to binary > (have ‘float’ and ‘float
(*)(float **, long int,  long int,  short int *)’)
array_processing.c:10:13: error: lvalue required as left operand of assignment
make: *** [array_processing.o] Error 1

Upvotes: 0

Views: 1430

Answers (2)

Andreas Fester
Andreas Fester

Reputation: 36630

It's a typo: use

if((ArrayIn[i][j]>maxvalue)==1){
                     ^
                    !!!

and

    maxvalue = ArrayIn[i][j];
       ^
      !!!

You have declared a variable float maxvalue (non-capital 'v'), and a function maxValue(...) (capital 'v') - so the compiler tries to use the function as second operand of the comparison when you use maxValue there.

Keep in mind that C is case significant - so maxvalue and maxValue are different symbols, but they need to be used properly.

Ideally, try to avoid such issues by choosing better names - for example, use getMaxValue() or calculateMaxValue() for the function name.

Besides that, if((ArrayIn[i][j]>maxvalue)==1) is unnecessarily complex - simply use

if(ArrayIn[i][j] > maxvalue)

Upvotes: 2

Kerrek SB
Kerrek SB

Reputation: 477040

You managed to outsmart yourself. maxValue is the name of the function, and maxvalue the name of the local variable. Check your spelling again. And pick better names next time.

Upvotes: 8

Related Questions