3 ms·
Does that mean all programs which use qsort have "Undefined Behavior"™? Just those which use nontransitive comparison functions? Only those which encounter non-
by mac3n 3y ago
Does that mean all programs which use qsort have "Undefined Behavior"™?
Just those which use nontransitive comparison functions?
Only those which encounter non-transitivity?
- o11c 3y agoPrograms that use subtraction to implement comparisons have two different kinds of UB - the integer overflow, and the invalid argument (nontransitive function) to qsort. It's possible to implement a nontransitive function without the first UB though. Note however that the UB only actually happens if the dynamically-passed values are more than INT_MAX apart. So e.g. if the values are never negative in practice, or limited to a small maximum, there is no UB.