是否需要main()? [英] Is main() required?

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

问题描述

在C ++中,程序的执行在main()执行之前就已经开始了。

首先执行在main

范围之外定义的静态变量的初始化。我可以想象一个程序,整个工作

可以在静态变量的构造函数和析构函数中完成。

(这不是最终的OOP程序,只是创建和删除一个对象?$

C ++标准是否要求具有(虚拟)main()函数

in这样的程序?


FZ

In C++ execution of a program starts already before execution of main().
The initialization of static variables defined outside the scope of main
is performed first. I could imagine a program where the whole job
can be done in the constructor and destructor of a static variable.
(Wouldn''t that be the ultimate OOP program, just the creation and
deletion of an object?)
Does the C++ standard require to have a (dummy) main() function
in such a program?

F.Z.

推荐答案

* Fred Zwarts:
* Fred Zwarts:

C ++标准是否需要在程序中具有(虚拟)main()函数?

Does the C++ standard require to have a (dummy) main() function
in [...] a program?




托管实现(这意味着一个声称是完整的C ++,一个你用
用于创建普通计算机的普通应用程序),是的。


用于独立实现(典型的嵌入式系统编程),

没有。


-

答:因为它弄乱了订单人们通常会阅读文字。

问:为什么会这样d东西?

A:热门发布。

问:usenet和电子邮件中最烦人的是什么?



For a hosted implementation (that means one claiming to be full C++, one you
use to create ordinary applications for general computers), yes.

For a freestanding implementation (typical for embedded systems programming),
no.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


嗨Freds,

是的,你有一个有趣的观点。首先,没有人宣称

C ++是一种终极的OOP语言。

其次,这几乎是Java在创建
$ b时带入的内容$ b终极OOP(有其自身令人头疼的事情)。


没有入口点就没有程序可以执行,所以如果全局变量

被用作条目当我们在全球范围内创建两个对象获得
时会发生什么?

谁控制了该程序?并行运行?这是什么

意图?或者如果序列..为什么一个对象会追随其他?


因此main是必要的(在c ++中它是一个全局的函数)和(java它

是类的静态成员函数)因此,我们不保证C ++中全局对象的执行方法,但是我们保证流程通过指定一个入口点的代码,即使在OOP中也是绝对必要的。



Fred Zwarts <˚F****** @ KVI.nl>。在消息中写道

news:di ********** @ info.service.rug.nl ...

在C ++中执行程序启动已经在执行main()之前。

首先执行在main

范围之外定义的静态变量的初始化。我可以想象一个程序,整个工作

可以在静态变量的构造函数和析构函数中完成。

(这不是最终的OOP程序,只是创建和删除一个对象?$

C ++标准是否要求具有(虚拟)main()函数

in这样的节目?


FZ

Hi Freds,
yes its an interesting view you have. First, No one ever proclaimed that
C++ is a ultimate OOP language.
Second, this is almost what Java has brought into it while creating the
ultimate OOP (with its own headaches ofcourse).

No program can be executed without the entry point, so if global variables
were used as entry points, what happens when we have two objects getting
created under global scope?
who takes control of the program? Do the run parallely ? Is that what is
intended ?? or if serial .. why should one object come after other ?

hence main is necessary ( in c++ it is a global fucntion ) and in (java it
is a static member function of a class )

hence, we do not guarantee the execution method of global objects in C++,
but we guarantee the flow of the code by specifying an entry point, which is
absolutely necessary even in OOP..


"Fred Zwarts" <F.******@KVI.nl> wrote in message
news:di**********@info.service.rug.nl...
In C++ execution of a program starts already before execution of main().
The initialization of static variables defined outside the scope of main
is performed first. I could imagine a program where the whole job
can be done in the constructor and destructor of a static variable.
(Wouldn''t that be the ultimate OOP program, just the creation and
deletion of an object?)
Does the C++ standard require to have a (dummy) main() function
in such a program?

F.Z.


Alf P. Steinbach写道:
Alf P. Steinbach wrote:
* Fred Zwarts:
* Fred Zwarts:

C ++标准是否需要在程序中具有(虚拟)main()函数?

Does the C++ standard require to have a (dummy) main() function
in [...] a program?



对于一个独立的实现(典型的嵌入式系统编程),没有。



For a freestanding implementation (typical for embedded systems
programming), no.




只是为了说清楚:在这种情况下,C ++标准并不要求它,但实现可能非常需要它。



Just to make it clear: The C++ standard doesn''t require it in this case, but
the implementation may very well require it.


这篇关于是否需要main()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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