为什么 memmove 使用 void * 而不是 char * 作为参数?

Why does `memmove` use `void *` as parameter instead of `char *`?

c库函数memmove的定义如下:

void* memmove(void *s1, const void *s2, size_t n)
{
    char *sc1;
    const char *sc2;

    sc1 = s1;
    sc2 = s2;
    ...
}

我想知道为什么我们需要使用 void*const void* 作为参数类型。为什么不直接char*const char*

更新

int test_case[] = {1, 2, 3, 4, 5, 6, 7, 8, 10};

memmove(test_case+4, test_case+2, sizeof(int)*4);

输出: test_case = {1, 2, 3, 4, 3, 4, 5, 6, 10}

void * 是通用指针类型。 memmove 应该操作内存,而不管内存中的对象是什么类型。

memcpy 类似。将它与使用 char * 参数的 strcpy 进行比较,因为它应该操作字符串。

如果使用 char*const char*,那么在对其他类型调用 memmove 时,我们必须始终转换为 char*

通过使用 void*const void*,我们可以编写更短的代码,并且转换没有性能开销。