是否有可能写不使用main()函数的程序? [英] Is it possible to write a program without using main() function?

查看:158
本文介绍了是否有可能写不使用main()函数的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到这个问题在面试时问:

I keep getting this question asked in interviews:

写一个程序,而无需使用的main()功能?

Write a program without using main() function?

我的一个朋友用宏给我看了一些code,但我无法理解。

One of my friends showed me some code using Macros, but i could not understand it.

所以,问题是:

难道真的有可能来编写和编译程序,而不的main()

Is it really possible to write and compile a program without main()?

推荐答案

在标准C ++需要的功能,所以这个问题的标准C没有意义++。

Within standard C++ a main function is required, so the question does not make sense for standard C++.

标准C ++例如,你可以写一个Windows特定程序,并使用微软的自定义启动功能之一(wMain,WinMain函数,wWinmain)之外。在Windows中,你也可以写程序作为一个DLL和使用RUNDLL32运行它。

Outside of standard C++ you can for example write a Windows specific program and use one of Microsoft's custom startup functions (wMain, winMain, wWinmain). In Windows you can also write the program as a DLL and use rundll32 to run it.

除此之外,你可以让你自己的小运行​​时库。有一段时间,这是一个普遍的运动。

Apart from that you can make your own little runtime library. At one time that was a common sport.

最后,你可以弄巧,并反驳说,根据标准的ODR规则不是拿来主义,所以任何计划资格。呸!虽然除非面试官有幽默感的不同寻常的良好的感觉(而且他们也不会提出这样的问题,如果他们有),他们会不会认为这是一个很好的答案。

Finally, you can get clever and retort that according to the standard's ODR rule main isn't "used", so any program qualifies. Bah! Although unless the interviewers have unusual good sense of humor (and they wouldn't have asked the question if they had) they'll not think that that's a good answer.

这篇关于是否有可能写不使用main()函数的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆