且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从加入一个变量段错误

更新时间:2023-12-04 23:12:40

您需要动态地分配你的节点(使用malloc)。

You need to dynamically allocate your nodes (using malloc).

当你拥有了它,你的新节点声明的堆栈。当拆分函数返回时,新的节点不再有效的内存。

As you have it, your new node is declared on the stack. When the split function returns, that new node is no longer valid memory.

添加一个变量会导致段错误,因为该变量改变了堆栈造成不同的效果,布局时,函数返回。

Adding a variable causes a segfault because that variable changes the layout of the stack causing slightly different behavior when the function returns.