所以简而言之,我想这样做:
createProcesswithPipe(pointer++, executes, execute);
但在这里,指针从未增加到下一个函数(我尝试打印它,它一直打印0,直到我的计算机最终崩溃。)
现在我做的是:
pointer++;
createProcesswithPipe(pointer, executes, execute);
看起来合乎逻辑,对吧?
现在我得到这个错误:分割错误(核心转储)
好吧,既然我得到了一些信息,我也会分享更多,因为分段故障似乎是这里的主要问题。。。
所以这是一个递归函数,当我输入它时,我做的第一件事就是打印出指针值(这只是为了检查它),当我的代码不包含递归部分时,当我注释掉这个部分时:
createProcesswithPipe(pointer, executes, execute);
开始时的printf工作并打印0,然后我得到分段错误。
当它没有被注释掉时,它甚至不会打印出第一个0,它只是关闭了带有错误分段错误的程序。
换句话说,当它没有被注释掉时,整个程序似乎在到达代码的那一部分之前就崩溃了?
此代码:
createProcesswithPipe(pointer++, executes, execute);
与相同
createProcesswithPipe(pointer, executes, execute);
pointer++;
另一方面,此代码:
pointer++;
createProcesswithPipe(pointer, executes, execute);
与相同
createProcesswithPipe(pointer + 1, executes, execute);
pointer++;
使用递增前
createProcesswithPipe(++pointer, executes, execute);
++指针在计算表达式之前递增指针而指针++在递增之前对其求值。如果使用预增量,则不需要额外的行。或者,你可以这样做:
createProcesswithPipe(pointer+=1, executes, execute);