void _memmove(void * src, void * des, int n) { unsigned char *s; unsigned char *t; assert(src!=NULL); assert(des!=NULL); if(n<=0 || des==src)return;
if(des>src) { s = (unsigned char*)src+n-1; t = (unsigned char*)des+n-1; while(n--)*t-- = *s--; }else /* des<src */ { s = (unsigned char*)src; t = (unsigned char*)des; while(n--)*t++ = *s++; } }
全局变量放在数据段里(位置固定,程序加载时刻决定),局部变量放在堆栈里(位置随机,运行时刻决定),一般编译器好象都这样干. |