我正在学习,这是一个简单的测试。
scl.h
#ifndef sclh
#define sclh
typedef struct{
int value; }listnote;
struct ElemSCL {
listnote info;
struct ElemSCL*next;
};
typedef struct ElemSCl Tipo;
typedef Tipo *Mangiato;
void Addscl(Mangiato*scl, int e) ;
#endifprove.c
#include "scl.h"
#include<stdlib.h>
#include<stdio.h>
//create node
void Addscl (Mangiato *scl, int e) {
Mangiato temp;
temp = *scl;
*scl= (Tipo*) malloc(sizeof(Tipo));
*(scl)->info.value= e;
*(scl)->next = temp;
}Main.c
#include<stdio.h>
#include<stdlib.h>
#include"scl.h"
int main()
{
Tipo *scl= NULL;
Addscl (&scl,3);
printf("%d", *(scl)->info.value);
}
return 0;
}我得到以下错误:
main.c:9:22: error: dereferencing pointer to incomplete type ‘Tipo {aka struct ElemSCl}’
printf(" %d", *(scl)->info.value);
^~
prove.c: In function ‘Addscl’:
prove.c:9:29: error: invalid application of ‘sizeof’ to incomplete type ‘Tipo {aka struct ElemSCl}’
*scl= (Tipo*) malloc(sizeof(Tipo));
^~~~
prove.c:10:7: error: ‘*scl’ is a pointer; did you mean to use ‘->’?
*(scl)->info.value= e;
^~
->
prove.c:11:7: error: ‘*scl’ is a pointer; did you mean to use ‘->’?
*(scl)->next = temp;
^~
->发布于 2021-04-26 14:01:30
表达式*(scl)->info.value与*(scl->info.value)相同。也就是说,取消对value成员的引用。
您需要(*scl)->info.value来解除对scl指针的引用。
至于sizeof问题,您有
struct ElemSCL { ... };和
typedef struct ElemSCl Tipo;密切注意拼写...在typedef中使用小写的l,应该是大写的L
typedef struct ElemSCL Tipo;https://stackoverflow.com/questions/67261482
复制相似问题