I'm having an issue with my comparison function for qsort. I've got an array, mGames, of type ListEntry. ListEntry looks like this:
struct ListEntry
{
bool mLocal;
int mLastTurnTime;
};
That's actually rather oversimplified, there's more data in there but it's not being used in the sorting so I omitted it. Anyway, I'm trying to make it so that entries that have mLocal set to true are ordered first. Problem is, I can't get qsort to order my array whatsoever. Here's the comparison function:
int compare(const void* a, const void* b)
{
ListEntry* e1 = (ListEntry*)a;
ListEntry* e2 = (ListEntry*)b;
if (e1->mLocal && e2->mLocal)
return 0;
return e1->mLocal ? -1 : 1;
}
and my call to it:
qsort(mGames, mNumGames, sizeof(ListEntry), compare);
where mNumGames is the number of games in the array (7 in my current test case), and mGames is defined as:
ListEntry mGames[MAX_GAMES]; // where MAX_GAMES is 50
When I step into the compare method, e1 and e2 contain their data as expected (as in, I'm not accessing garbage memory or didn't dereference things right).
The weird thing is, no matter how I change that comparison method, I can't get the order to change at all. I must be overlooking something really obvious.
qsortanyway, usestd::sort.