Get max from array

BlitzMax Forums/BlitzMax Programming/Get max from array

sczerbiak(Posted 2006) [#1]
Ok.. so i have this function in c:

#include <math.h>

double bbMax2(double values[], int count)
{
    double result = values[0];

    int x;
    for (x = 0; x < count; x++)
    {
        if (values[x] > result)
	    result = values[x];
    }

    return result;
}


and this as example.bmx

SuperStrict

Import "example.c"

Extern
    Function Max2:Double(values:Double[], count:Int) = "bbMax2"
EndExtern

Local array:Double[] = [3:Double, 5:Double]
 
Print Max2(array, array.length)



The result showld be 5.0000...

but it is something like this:

2.1252855428782069e-314

am i missing something!?


skidracer(Posted 2006) [#2]
try
    Function Max2:Double(values:Double Ptr, count:Int) = "bbMax2"


(I think you are currently passing the array object not a pointer to the first element)


sczerbiak(Posted 2006) [#3]
ok ;) it works that way.

thanks :D


H&K(Posted 2006) [#4]
That was so obvious once skid said. I looked at this for at least 20mins last night, and could see what was wrong with it at all.