gpt4 book ai didi

通过指向结构体指针的指针更改变量

转载 作者:行者123 更新时间:2023-11-30 17:59:11 25 4
gpt4 key购买 nike

我试图通过一个结构来更改 int 变量,该结构常量指向另一个结构,其中一个字段是该变量。我在编译中收到一个警告和一个错误。任何人都可以解释为什么以及我如何使用这段代码来完成他的任务?

代码是:

typedef struct
{
struct TEEC_Session *ptr_struct;
} Context_model;

typedef struct
{ int t_S;
} Session_model;

void Attribution(Context_model* context,Session_model* session )
{
(*context).ptr_struct = session;

}

void change_t_S(Context_model* context )
{
(*(*context).ptr_struct).t_S = 5; // I Want to change t_S to 5 using only the

context structure

}

main()
{
Context_model context;
Session_model session;

Attribution(&context,&session);

// Now I want to change t_S using the context
change_t_S(&context);
}

最佳答案

修改Context_model的定义为

typedef struct
{
Session_model *ptr_struct;
} Context_model;

并将其移至 Session_model 定义下方。

您的代码中未定义 TEEC_Session 结构。

关于通过指向结构体指针的指针更改变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11671695/

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