[英]ANSI C - what does struct **variable mean?
In ANSI C, what does struct **variable
mean? 在ANSI C中, struct **variable
是什么意思? For example: 例如:
typedef struct estructuraPersona{
char nombre[30];
char apellido[30];
} tyPersona;
typedef tyPersona *ptrTyPersona;
ptrTyPersona functionFive(ptrTyPersona *ptrPtrTyPersona) {
ptrTyPersona *pptP= (ptrTyPersona *)malloc(sizeof(tyPersona));
if (*pptP == NULL) {
printf("Error al crear nuevo nodo!");
return NULL;
}
return pptP;
}
I get an error when compiling the code. 编译代码时出错。
Do 做
ptrTyPersona* functionFive(ptrTyPersona *ptrPtrTyPersona){
instead of 代替
ptrTyPersona functionFive(ptrTyPersona *ptrPtrTyPersona){
This function 这个功能
ptrTyPersona functionFive(ptrTyPersona *ptrPtrTyPersona){
ptrTyPersona *pptP= (ptrTyPersona *)malloc(sizeof(tyPersona));
if(*pptP == NULL){
printf("Error al crear nuevo nodo!");
return NULL;
}
return pptP;
}
makes no sense because parameter ptrPtrTyPersona
is not used. 没有意义,因为没有使用参数ptrPtrTyPersona
。
I can suspect that the function should do the following 我可以怀疑该功能应该执行以下操作
ptrTyPersona functionFive(ptrTyPersona *ptrPtrTyPersona){
*ptrPtrTyPersona = ( ptrTyPersona )malloc(sizeof(tyPersona));
if(*ptrPtrTyPersona == NULL){
printf("Error al crear nuevo nodo!");
}
return *ptrPtrTyPersona;
}
As for the original function then function return type is ptrTyPersona
but the function returns pointer pptP
of type ptrTyPersona *
至于原始函数,那么函数返回类型是ptrTyPersona
但函数返回pptP
类型的指针ptrTyPersona *
And in this statement 并在此声明中
ptrTyPersona *pptP= (ptrTyPersona *)malloc(sizeof(tyPersona));
there is allocated structure tyPersona so you should use pointer of type ptrTyPersona
to refer the allocated memory but you use pointer of type ptrTyPersona *
有分配结构tyPersona所以你应该使用类型为ptrTyPersona
指针来引用分配的内存,但你使用ptrTyPersona *
类型的ptrTyPersona *
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.