I found the following in the standard, which confirms the above is a hack. I thought it would be fine... it definitely won't work with std::sort. But even with qsort the behaviour violates the requirement of a total ordering

ISO/IEC 9899:201x, 7.22.5
When the same objects (consisting of size bytes, irrespective of their current positions
in the array) are passed more than once to the comparison function, the results shall be
consistent with one another. That is, for qsort they shall define a total ordering on the
array, and for bsearch the same object shall always compare the same way with the