Topic: Proposal: ~main() - as global destructor
Author: ivanov@iiasa.ac.at (Pavel IVANOV)
Date: Tue, 24 Jan 1995 17:50:29 GMT Raw View
Thanx guy for the usefull discussion of my proposal (~main())
I understood that there are another mechanisms to deallocate
globals and from the other hand ~main() is useless because
main() is not a only 'constructor' of program instance, but
it has a code, which is aimed to run something after starting.
Beside that realization of ~main() will be incompatible
with plain C language. The more proper way is to create
application instance class or at least to use atexit()
Thanx
Ivanov Pavel | Water Resources Project
International Institute | Parkwing, room 144
for Applied Systems Analysis | Phone: +43 2236 807
Laxenburg, Schlossplatz 1 | Fax: +43 2236 71313
A-2361, Austria | Email: ivanov@iiasa.ac.at
WINDOWS | DIE!
Author: ivanov@iiasa.ac.at (Pavel IVANOV)
Date: Wed, 18 Jan 1995 08:35:26 GMT Raw View
Hi all!
All we know that in c and c++ languages every program must have a program
startup function - main() (sometimes it called as WinMain(), LibMain(), etc)
In terms of OOP main() functions is a kind of constructor of program instant.
If there is constructor must exist and destructor! In other words function
~main() - destructor of program instant. main() and ~main() are the places,
for instance, for allocation and freeing global arrays or initialization
and deleting static members of classes:
class A
{
....
public:
static char *s_lpch;
public:
A();
~A();
....
};
main()
{
...
A::s_lpch=new char[128];
...
}
~main()
{
...
delete [] A::s_lpch;
...
}
I'm not a specialist in computer languages, I'm programmer, more or
less experienced in C and C++. I think that realization of such
proposal is quite possible (~main() function as part of C++ standard
feature).
I wonder what is the opinion of specialists (and non-specialists too)
on this matter?
Ivanov Pavel | Water Resources Project
International Institute | Parkwing, room 144
for Applied Systems Analysis | Phone: +43 2236 807
Laxenburg, Schlossplatz 1 | Fax: +43 2236 71313
A-2361, Austria | Email: ivanov@iiasa.ac.at
WINDOWS | DIE!
Author: Viktor Yurkovsky <n4mation@panix.com>
Date: 18 Jan 1995 16:43:56 GMT Raw View
Seems totally unnecessary and not very logical:
main() is not a constructor, main is not a classname,
why would anyone want a ~main()?
main actually has code. If you use new in main, use delete in main
when you are done.
If you really want, create an Application class (MFC does it).
-------------------------------
n4mation@panix.com |
Data In Formation Inc. |
|
Victor Yurkovsky |
|
Compiler maker |
|
Special discounts for |
weddings and funerals. |
_______________________________|
Enjoy your compile time. I WILL take it away from you!