gpt4 book ai didi

c - 如何从指针访问结构成员

转载 作者:太空宇宙 更新时间:2023-11-04 00:43:31 25 4
gpt4 key购买 nike

<分区>

在将 void* 指针传递给该结构的基地址时,我无法访问该结构的成员。谁能提供解决方案或向我解释错误?现在我收到消息“goroutines.c:142:31: error: request for member ‘qtail’ in something not a structure or union”

    //Channel struct
struct channel{
int magicnumber;
int length;
int capacity;

struct gcb* qhead; //head of the queue
struct gcb* qtail; //tail of the queue
};


void *makeChannel(int dataLength, int capacity){
if( dataLength <= 0){
panic( "data length must be greater than zero" );
}
if( capacity < 0){
panic( "capacity must be non-negative" );
}
struct channel* ch = (struct channel* )malloc( dataLength * capacity );
ch->magicnumber = 0x1ca91ac3;
ch->capacity = capacity;
ch->length = 0;
return ch;
}

void sendChannel(void *channel, void *fetchAddress){
if( capChannel( channel ) == lenChannel( channel ) ){

(struct channel* )&channel->qtail->next = head;
}
}

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