0 c function control-flow setjmp
我有一个function()电话anotherFunction().在里面anotherFunction(),有一个if语句,当满足时返回if并且不返回main().你怎么做到这一点?谢谢.
你不能在"标准"C中做到这一点.你可以用setjmp和longjmp来实现它,但强烈建议不要这样做.
为什么不直接返回值anotherFuntion()并根据该值返回?像这样的东西
int anotherFunction()
{
// ...
if (some_condition)
return 1; // return to main
else
return 0; // continue executing function()
}
void function()
{
// ...
int r = anotherFuntion();
if (r)
return;
// ...
}
Run Code Online (Sandbox Code Playgroud)
_Bool如果函数已被用于返回其他内容,则可以返回或返回指针
| 归档时间: |
|
| 查看次数: |
108 次 |
| 最近记录: |