This version of mystructcmp uses explicit comparisons,
rather than the more obvious subtractions,
to decide whether to return a negative, zero, or positive value.
In general, it's safer to write comparison functions this way:
subtraction can easily overflow
(and cause either an abort or a quiet wrong answer)
when a very large positive number is compared with
a very large negative number.
(Of course,
in this example,
overflow would be unlikely in any case.)
back
This page by Steve Summit
// Copyright 1995-2004
// feedback