gpt4 book ai didi

c - 如何从对用户隐藏定义的结构中取消引用成员?

转载 作者:行者123 更新时间:2023-11-30 16:22:55 24 4
gpt4 key购买 nike

Payload_Manager.h

typedef struct ATEIS_Payload_s* pATEIS_Payload;

Payload_Manager.c

#include "Payload_Manager.h"

struct __attribute__((__packed__))ATEIS_Payload_s //payload
{
uint32_t Addr;
uint16_t Cmd;
uint16_t Len;
uint8_t Data[];
};

DNM_Manager.h

#include "Payload_Manager.h"

typedef struct DNM_s* pDNM;

pDNM DNMManager_Ctor(pDNM this, pATEIS_Payload src);

DNM_Manager.c

#include "Payload_Manager.h"

struct DNM_s
{
uint32_t Addr;
uint32_t SerialNo;
uint32_t SubnetMask;
uint16_t Tick;
uint8_t Name[NAME_SIZE];
}DNMSet[SET_SIZE], DNMTemp;

pDNM DNMManager_Ctor(pDNM this, pATEIS_Payload src)
{
memcpy(this->Name, &src->Data[NAME], NAME_SIZE); //ptr to incomplete class type is not allowed
this->Addr = src->Addr; //ditto
this->SerialNo = *(uint32_t*)&src->Data[SN]; //ditto
this->SubnetMask = *(uint32_t*)&src->Data[SUBMASK]; //ditto
this->Tick = 0;
return this;
}

main.c

#include "Payload_Manager.h"
#include "DNM_Manager.h"

pDNM DNM_temp = NULL;
DNM_temp = DNMManager_New(); //get one DNM
DNM_temp = DNMManager_Ctor(DNM_temp, pl_p); //init DNM_temp by pl_p

文件 DNM_Manager.c 需要知道 ATEIS_Payload_s 的声明,否则无法取消引用它。

除了在 DNM_Manager.c 中再次声明 ATEIS_Payload_s 之外,我还能做什么?

谢谢。

最佳答案

正如 Groo 所建议的,实现者必须向用户提供操作成员的功能。这是我的代码片段:

uint32_t PayloadManager_GetAddr(ATEIS_Payload_s* this)
{
return this->Addr;
}

关于c - 如何从对用户隐藏定义的结构中取消引用成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54215492/

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