Pointers Clang和gcc编译器为我的代码提供了不同的错误和警告消息/

Pointers Clang和gcc编译器为我的代码提供了不同的错误和警告消息/,pointers,gcc,clang,Pointers,Gcc,Clang,我尝试编写一个测试代码来获取指针返回值: #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 '\

我尝试编写一个测试代码来获取指针返回值:

#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支持嵌套函数和


看起来您的函数是意外嵌套的;只要将它移到主函数之外,它就会继续工作。

GCC支持嵌套函数和

看起来您的函数是意外嵌套的;只要把它移到主功能之外,它就会继续工作

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.