有陷阱,要考虑溢出问题
int comp_int(int var1, int var2)/* return value < 0: means var1 < var2; * = 0: means var1 = var2; * > 0: means var1 > var2;*/{ int bit_width, msb, rtnvar; bit_width = sizeof(int) << 3; msb = var2 >> (bit_width -1) - var1 >> (bit_width -1); if (msb) rtnvar = msb; else rtnvar = var1 - var2; return rtnvar;}