What's wrong with phillips's code
Phillips:
I can immediately see two problems in your code, which causes the problem you see on pgCC compiler.
First:
Code:
inline int qsortCompare(const void *a , const void *b)
{
D d1 = *(D*)a;
D d2 = *(D*)b;
return ( d1.ia - d2.ia);
}
You are un-necessarily creating new objects here, maybe to slow qsort() down a bit to make it look bad? You could have done this;
Code:
inline int qsortCompare(const void *a , const void *b)
{
return ( ((D*)a)->ia - ((D*)b)->ia);
}
Second, what causes it fail on pgCC is the third parameter on this line
Code:
qsort(&v1[0],v1.size(),sizeof(v1[0]),qsortCompare);
What do you suppose sizeof(v1[0]) to be? Looks to me, v1[0] is a reference to a D object, NOT an instance of D object. Hence sizeof of it evaluate to 4 bytes, which is NOT the size of D object. That's why it fails. You are fortunate that VC interpreted v1[0] differently when it evaluate the sizeof.
Change it to sizeof(D), try again. I am pretty sure it will work then. But let me and others know what is your finding.