gpt4 book ai didi

c - 错误 : dereferencing pointer to incomplete type

转载 作者:行者123 更新时间:2023-12-02 08:42:27 25 4
gpt4 key购买 nike

查看了许多与此相关的其他 SO 帖子,但没有一个能够帮助我。所以,我定义了以下结构:

 typedef struct
{
int created;
double data;
int timeLeft;
int destination;
}dataPacket;

typedef struct
{
dataPacket *array;
int currIndex;
int firstIndex;
int nextTick;
int maxLength;
int length;
int stime;
int total;


}packetBuffer;

typedef struct{
int mac;
struct wire *lconnection;
struct wire *rconnection;
int numRecieved;
struct packetBuffer *buffer;
int i;
int backoff;
}node;

typedef struct{
float length;
float speed;
int busy;
struct dataPacket *currPacket;
struct node *lnode;
struct node *rnode;
}wire;

然后我尝试使用以下函数:

    int sendPacket(node *n, int tick)
{
if(n->buffer->length > 0)
{
if(n->backoff <= 0)
{
if (n->lconnection->busy != 0 || n->lconnection->busy != 0)
{
n->i++;
n->backoff = (512/W * genrand()*(pow(2,n->i)-1))/TICK_LENGTH;
}
else
{
n->lconnection->busy = 1;
n->rconnection->busy = 1;
n->lconnection->currPacket = n->buffer[n->buffer->currIndex];
n->rconnection->currPacket = n->buffer[n->buffer->currIndex];
}
}
else
{
n->backoff--;
}
}
}

每次尝试访问缓冲区、lconnection 或 rconnection 的成员时,我都会收到标题中描述的错误。

最佳答案

struct packetBuffer *buffer;

您已经定义了一个类型 packetBuffer(一个匿名结构的 typedef)。

你还没有定义struct packetBuffer

在没有现有类型 struct packetBuffer 的情况下,编译器将其视为不完整类型,假设您稍后会完成它。声明

struct packetBuffer *buffer;

是完全合法的,但是您不能取消引用 buffer 除非类型 struct packetBuffer 可见。

只需删除 struct 关键字即可。

(我个人的偏好是放弃 typedef 并始终将结构类型称为 struct whatever,但这是风格和品味的问题。)

关于c - 错误 : dereferencing pointer to incomplete type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15345542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com