我尝试制作一个测试代码来获取指针返回值:
#include <stdio.h>
int main(void){
char myStrcpy(char *str1,char *str2){
while(*str2 != '\0'){
*str1++ = *str2++;
}
*str1 = '\0';
return str1;// return the final pointer that should point to the '\0'
}
char *reValue;
char string1[] = "abcd";
char string2[10];
reValue = myStrcpy(string2,string1);
reValue--;//now it should point to the last character which is `d`
printf("this value of string 2 is %s\n",string2);
printf("the return value the function is %c\n",*reValue);
return 0;
}
gcc 编译此代码时没有错误和警告,但 clang 给了我 4 个错误:
my_stcpy.c:4:40: error: expected ';' at end of declaration
char* myStrcpy(char *str1,char *str2){
^
;
my_stcpy.c:14:2: error: use of undeclared identifier 'reValue'
reValue = myStrcpy(string2,string1);
^
my_stcpy.c:15:2: error: use of undeclared identifier 'reValue'
reValue--;
^
my_stcpy.c:17:50: error: use of undeclared identifier 'reValue'
printf("the return value the function is %c\n",*reValue);
^
4 errors generated.
任何的想法?