我可以安全地在GCC复合语句表达式中使用return吗?
例如,我定义宏
#define CHECK_FUNC_RESULT(func) \
({ \
int result = func(); \
if (!result) return; \
result; \
})
Run Code Online (Sandbox Code Playgroud)
并以这种方式在代码中的某处使用它:
int function1()
{
if (some_condition)
return 0;
...
return 1;
}
void function2()
{
if(CHECK_FUNC_RESULT(function1)) {
... to do something
}
}
Run Code Online (Sandbox Code Playgroud)
我可以期待从function2(在some_condition == true)返回而没有任何未定义的行为吗?
| 归档时间: |
|
| 查看次数: |
417 次 |
| 最近记录: |