Nothing jumps out at me as being incorrect. I assume line 20 is the deliberate bug.
Since the closing "}" is missing from what you pasted, I don't know if this is the complete program or if there is something after line 33 that could be causing problems. Could the seg fault be coming after what you have posted?
I don't think there is a problem with the comparison function. I took what was posted, added my own printout statements at the end of main, and ran it. There were no segmentation faults. (After I fixed the "deliberate bug", the output even looked nice and consistent).
As I said before, I suspect the error is in the remainder of the code that was not posted.
I don't think there is a problem with the comparison function.
It does not satisfy the requirements for strict weak ordering.
Just imagine what would happen if you declared two variables as follows.
1 2 3
// i a b
test t1 = {-1, 1, 0};
test t2 = {-1, 2, 0};
cmp(t1, t2) would return false which means t1 should be positioned after t2,
but cmp(t2, t1) would also return false which means t2 should be positioned after t1.
> there are no guarantees about what will happen.
>> There were no segmentation faults.
no checks are done, no behaviour is expected
¿do you still don't understand what undefined means?
> cmp(t1, t2) would return false(...)
> but cmp(t2, t1) would also return false(...)
> This is a contradiction!
No, in that case they are equivalent.
the problem is when cmp(t1, t2) and cmp(t2, t1) returns true.