0ct0cat / spexamples

Automatically exported from code.google.com/p/spexamples
0 stars 0 forks source link

整数的比较函数实现好像有问题 #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
int int_cmp(void* a, void* b)
{
    return (int)a - (int)b;
}
是把a和b的地址强转成int型后比较,并非比较a,b实际的值

应该是
int int_cmp(void* a, void* b)
{
    return *(int *)a - *(int *)b;
}

Original issue reported on code.google.com by xuerubin...@163.com on 8 Aug 2010 at 4:31

GoogleCodeExporter commented 9 years ago
谢谢。这个没错:a/b并不是指针,是一个整数,所以不能转��
�成指针再取内容。

Original comment by xianji...@gmail.com on 17 Aug 2010 at 9:28