退出状态一定得通过 os.exit() 指定吗?在 main() 里调用 os.exit() 会让我无法使用 defer,并产生以下诊断。
Error: Unreachable defer statement due to diverging procedure call at the end of the current scope
这条 GitHub Discussion 提出了下面的办法。
Odin 的 main 过程能返回一个值吗? GitHub Discussion (https://github.com/odin-lang/Odin/discussions/3097) 比如,要模仿 C 的 int main(),可以另外定义一个能返回值的 proc,例如 run。然后 main 只需调用它,再根据它返回的错误作出合适的处理,比如用 os.exit() 以失败状态退出,或者执行应用需要的其他操作。
有没有其他办法,让 main() 指定退出状态,同时让 return、defer 和其余控制流程结构正常工作。