Hi everyone,
Has anybody been able to make SysBinarySearch work? This is what I have:
GLOBAL:
typedef struct {
ULong id;
int order;
} sort_element;
sort_element *pp_array;
IN A SUBROUTINE:
ULong searchpos;
(void) SysBinarySearch(&pp_array, (UInt) count, (UInt) sizeof(sort_element),
(SearchFuncPtr) &search_routine,
&id, (ULong) 0, &searchpos, false);
Right before this call, I've verified that the pp_array contains the proper
values, and that the COUNT variable is correct.
MY SEARCH ROUTINE:
static int search_routine(const VoidPtr searchData,
const VoidPtr arrayData, Long other) {
ULong search, data;
int answer;
CALLBACK_PROLOGUE
search = *((ULong *) searchData);
data = (*(sort_element *)arrayData)->id;
if (search < data)
answer = -1;
else if (search > data)
answer = 1;
else
answer = 0;
CALLBACK_EPILOGUE
return answer;
}
The SEARCH variable contains the correct value, but the value in DATA is
always wrong. Can anybody tell me what I'm doing wrong? (I have a feeling
it's the assignment statement DATA = ... that's the problem.)
TIA,
Tom Ward