D exit statement

倖福魔咒の 提交于 2019-12-06 03:53:55

问题


Does D have an exit statement, similar to the one in java, python, c/c++. Which will (big shocker) exit execution of the program? Something like exit();


回答1:


If you want exit, then use C's exit function.

import core.stdc.stdlib;

void main()
{
    exit(-1);
}

I'm not quite sure how that affects the D runtime and whatnot though. It might be that stuff doesn't get cleaned up like you'd normally want, or it might be just fine. I wouldn't really advise using it in general though, since there are usually better ways to handle exiting a program. But the declaration for the C function is in druntime, so it's easy to use it if you want it.



来源:https://stackoverflow.com/questions/7099956/d-exit-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!