Hello there I have the following code:
struct Edge
{
Node * nodeA, * nodeB;
int weight;
};
.
.
This is typedef'd to simply Edge elsewhere.
.
.
int cmp(const void *b, const void *a)
{
Edge * e1 = (Edge*)a;
Edge * e2 = (Edge*)b;
printf(" %d++", getWeight(e1));
printf(" %d++", getWeight(e2));
if (getWeight(e1) != getWeight(e2))
return (getWeight(e1) < getWeight(e2)) ? -1 : 1;
return 0;
}
void sortEdges(Edge ** edgeList, int numEdges)
{
qsort(edgeList, numEdges, sizeof(Edge*), cmp);
}
Valgrind tells me that I have an Invalid read of size 4, and when I output the value for the the edge weights I get totally unexpected results. I can only conclude that there is something wrong with my cast to an Edge* or that the sizeof is somehow not doing what I think it is. If you need any information please let me know.