我无法弄清楚为什么我自己会收到此警告clang
:
function_prototype_const_modifier.c:13:8: warning: initializing 'char *' with an
expression of type 'const char *' discards qualifiers
[-Wincompatible-pointer-types]
char *ptr1 = source;
^ ~~~~~~
1 warning generated.
代码很简单
#include<stdio.h>
char *my_strcpy(char *destination, const char *source);
int main(void) {
char str1[] = "this is something";
char str2[] = "123456789123456789";
my_strcpy(str2, str1);
puts(str2);
return 0;
}
char *my_strcpy(char *destination, const char *source) {
char *ptr1 = source;
char *ptr2 = destination;
while(*ptr1 != '\0') {
*ptr2++ = *ptr1++;
}
*ptr2 = '\0';
return destination;
}
任何的想法?