Assigning a variable to itself makes no sense. Also if you compile your program with warnings enabled it will complain about missing return statement due to missing else clause containing a return statement (or a return statement after the if statement). This should be sufficient:
#include <stdbool.h>
bool order(int *a, int *b)
{
bool swapNeeded = *a > *b;
if (swapNeeded) {
int oldA = *a;
*a = *b;
*b = oldA;
}
return swapNeeded;
}
This version also has a single exit point which in general makes it easier to reason about and debug a function.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…