菜鸟ing。作者: swangwu 时间: 2009-12-01 01:58 标题: 回复 #1 syukayo 的帖子 I have to write in English. It took me much time to have iBus work. But Chinese input method still can not work.
Last time, I did not explain the GCC pre-processing option clearly. The option is -E.
e.x.
gcc -E string-test.c -o string-test.i
The file of string-test.i has clear information about included .h files and data definition.
The option of -E is helpful for locating the compiling errors.作者: stevenwang87061 时间: 2009-12-01 09:52
我在写MEMMOVE这个库函数的时候,只看函数的声明,我只是简单的将它认为是和MEMCPY没什么区别,写完之后我看了看源代码,我发现我少考虑了一个问题,就是当目标BUFFER的首地址比源BUFFER的首地址要大,而且目标BUFFER的首地址与源BUFFER的首地址的差值小于COUNT时,如果你不加判断的话,会把源BUFFER的后面的字节内容给覆盖掉,移动后的BUFFER内容与源BUFFER内容不相同。
怎样处理这个问题呢,我们可以把用两个指针*P1,*P2分别指向目标BUFFER的首地址和源的首地址,然后把两个指针都加上COUNT,然后执行P1--和P2--;这时候P1和P2就分别指向目标BUFFER的最后一个字节的地址和源的最后一个字节的地址,然后开始循环赋值,这样就保证了源BUFFER的最后几个字节不会被覆盖。
我依照这个思想写了一下MEMMOVE,贴出来,大家多多指正。
void *memmove(void *p1, const viod *p2, int count)
{
char *ptr1;
const char *ptr2;