几个 WinMain 问题

发布于 2024-09-24 06:28:14 字数 410 浏览 5 评论 0原文

我有几个非常简单的问题。我在网上搜索了它们,但找到了不同的答案,所以我只想知道该遵循哪个。

所以,首先,我相信 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

勿忘心安 2024-10-01 06:28:14

我相信 WinMain 不是 C 或 C++ 标准,而只是由 Microsoft 添加来确定何时加载不同的 CRT 启动代码,对吗?

是的。所有 C 和 C++ 标准都将 main()(并且仅 main())定义为程序入口点(尽管其确切签名可能因语言和标准版本而异)。

其次,WinMain 是由操作系统以类似于动态链接的方式调用的,还是只是像 main 一样的程序启动点?

它实际上是从 main() 调用的。 Windows 程序中也有一个 main(),只是隐藏在 WinAPI 代码深处。

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?

Yes. All C and C++ standards define main() (and only main()) as the program entry point (although its exact signature may vary between languages and standard versions).

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?

It is actually called from main(). There is a main() in Windows programs too, just hidden deep within WinAPI code.

岁月无声 2024-10-01 06:28:14

尽管它们都是一样的,但将 C 视为 3 种语言:

  1. 标准独立式
  2. 标准托管实现 扩展
  3. 托管实现

您所描述的 (WinMain) 属于类型 3。

类型 3 程序在描述特定语言的计算机上运行他们使用的扩展

类型 2 有很多规则,但保证以该类型编写的程序在具有标准 C 编译器的每台计算机系统上(几乎每台带有键盘的计算机(包括 PDA、手表、. ..,...))。

类型 1 与类型 2 相同,只是少了一些规则和标准库——而且它应该适用于地球上的每个处理器。

该标准的文本来自 1999 2001 2004 2007。您可以在 ISO 站点 ( http://www.open-std.org/jtc1/sc22/wg14/www/standards)

Although it's all the same, consider C as being 3 languages:

  1. Standard free standing
  2. Standard hosted implementation
  3. Extended hosted implementation

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 1999 2001 2004 2007. You can find a PDF at the ISO site ( http://www.open-std.org/jtc1/sc22/wg14/www/standards )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文