gpt4 book ai didi

c - 设置 C 结构体的成员

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

some_struct = some_function;  //some_function returns a pointer to an instance of a struct
some_struct->num = 8; //num is an int

当我尝试将 gdb 与 p some_struct->num command 一起使用时,第二行会产生段错误。 ,上面写着 Cannot access memory at address 0x0

如何设置 some_struct->num 的值而不产生段错误?

最佳答案

您的函数返回 NULL 指针。确保它返回 some_struct 类型的有效内存。

关于c - 设置 C 结构体的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26327522/

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