Sorry if this is duplicate, but I can not find good answer.
I have code like this:
int cmp(size_t const a, size_t const b){
return (int) b - (int) a;
}
I am worrying of overflow. How function must be written in correct way?
I do not need correct value, I need result to be int
and to keep at least the sign, e.g. negative / positive / zero.
I also want to avoid any branching such those:
int cmp(size_t const a, size_t const b){
if (a == b)
return 0;
else
return a < b ? -1 : +1;
}