在c语言中(*this)是什么?

在c语言中(*this)是什么?,c,C,这个指针是什么? 它在linux中不起作用,但在visual studio中起作用 发生了什么事 #include <stdio.h> #include <string.h> #include<stdlib.h> typedef struct { char name[20]; int id; } person ; // this function is my main problem void

这个指针是什么? 它在linux中不起作用,但在visual studio中起作用 发生了什么事

    #include <stdio.h>
    #include <string.h>
    #include<stdlib.h>
    typedef struct {  char name[20]; int id; } person ;

    // this function is my main problem        
    void print(person *this){
         printf("%s %d\n",this->.name,this->id);  
    }

    int main(){
        person p, q;  
        strcpy(p.name, "a");
        p.id=60151234;
        strcpy(q.name, "b");
        q.id=60155678;

        print(&p);
        print(&q);
        system("pause");
        return 0;
    }
#包括
#包括
#包括
typedef结构{char name[20];int id;}个人;
//这个函数是我的主要问题
作废打印(人*本){
printf(“%s%d\n”,此->名称,此->id);
}
int main(){
人p,q;
strcpy(p.name,“a”);
p、 id=60151234;
strcpy(q.名称,“b”);
q、 id=60155678;
印刷品(p&p);
打印(&q);
系统(“暂停”);
返回0;
}

在C中,
这个
是一个普通的参数名,与任何其他名称没有区别


你可能使用C++编译器,其中<代码> < <代码>是关键字,当用作参数时会出错。

< p> C++,<代码> < <代码>是在类方法中作为对所涉对象的指针使用的保留字。它在C中不是保留字,因此在本例中它只是参数的名称


这段代码可以用gcc编译(前提是您将
This->.name
更改为
This->name
),但由于这个原因,它不会用g++编译。

这只是一个参数名。Visual Studio不附带C编译器。它不适合编写C程序。@KerrekSB Visual Studio肯定带有C编译器
cl.exe
可以编译C程序。它不完全符合C99标准,但您绝对可以使用Visual Studio编译C代码。@KerrekSB“它在linux中不起作用……但在Visual Studio中起作用”。他们可能是用g++在Linux上编译的,所以失败了。我用VS2013很好地编译了代码。@PCLuddite:好的,我明白了。谢谢。这不是关于C++的问题。KerrekSB我理解。我提到它是为了给OP的问题提供一个参考框架。我也理解这一点,但我只是觉得奇怪,关于X的问题的答案是从对Y的长篇大论开始的。这就像是对政客的采访。