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的值?
答案 0 :(得分:3)
您的函数返回NULL指针。确保它返回some_struct
类型的有效内存。