几个 WinMain 问题
我有几个非常简单的问题。我在网上搜索了它们,但找到了不同的答案,所以我只想知道该遵循哪个。
所以,首先,我相信 WinMain 不是 C 或 C++ 标准,而只是 Microsoft 添加的,用于确定何时加载不同的 CRT 启动代码,对吗?
其次,WinMain 是由操作系统以类似于动态链接的方式调用的,还是只是像 main 一样的程序启动点?
我为什么问?我主要使用 C 来编程 MCU。与软件相比,我更注重硬件,所以我喜欢 MCU,我发现它们以及为它们编程更“清晰”。
但当我开始对C语言本身及其标准感兴趣时,我发现它很难。我的意思是,例如,在 MCU 上,您不需要 main 的 int 返回类型,而在 win32 应用程序中,您需要与纯 main 不同的启动代码。
所以,我喜欢 C,但我发现它的标准有点老了。谢谢。
I have few very simple question. I searched a web for them, but I found different answers so I just want to know which to follow.
So, first, I believe WinMain is NOT C or C++ standart, but is only added by Microsoft to determine when to load different CRT startup code, am I right?
And second, is WinMain called by OS, in a way of lets say similiar to dynamic linking, or is it just program startup point like main?
Why I ask? I mainly used C for programming MCUs. I am more HW oriented than SW, so I like MCUs, I find them and programming for them more "clear".
But when I started to get interested about C language itself and its standart, I found that its very hard. I mean, for example, on MCU, you need no int return type of main, as well as in win32 app you need different startup code than pure main has.
So, I like C but I find its standart to be somehow old. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。所有 C 和 C++ 标准都将
main()
(并且仅main()
)定义为程序入口点(尽管其确切签名可能因语言和标准版本而异)。它实际上是从
main()
调用的。 Windows 程序中也有一个main()
,只是隐藏在 WinAPI 代码深处。Yes. All C and C++ standards define
main()
(and onlymain()
) as the program entry point (although its exact signature may vary between languages and standard versions).It is actually called from
main()
. There is amain()
in Windows programs too, just hidden deep within WinAPI code.尽管它们都是一样的,但将
C
视为 3 种语言:您所描述的 (WinMain) 属于类型 3。
类型 3 程序在描述特定语言的计算机上运行他们使用的扩展
类型 2 有很多规则,但保证以该类型编写的程序在具有标准 C 编译器的每台计算机系统上(几乎每台带有键盘的计算机(包括 PDA、手表、. ..,...))。
类型 1 与类型 2 相同,只是少了一些规则和标准库——而且它应该适用于地球上的每个处理器。
该标准的文本来自
1999200120042007。您可以在 ISO 站点 ( http://www.open-std.org/jtc1/sc22/wg14/www/standards)Although it's all the same, consider
C
as being 3 languages:What you describe (WinMain) belongs to type 3.
Type 3 programs work on computers which describe the specific extensions they use
Type 2 has a lot of rules, but offers a guarantee that programs written in that type will work the same on every computer system with a standard C compiler (virtually every computer with a keyboard attached (including PDA, wrist watch, ..., ...)).
Type 1 is the same as type 2 minus a few of the rules and the standard library -- and it should work for every processor on Earth.
The text of the Standard is from
1999200120042007. You can find a PDF at the ISO site ( http://www.open-std.org/jtc1/sc22/wg14/www/standards )