Mail Archives: djgpp/1996/09/16/00:45:22
>> There's nothing wrong with using exit to terminate a program, even
>> in main.
>
>Well, sure there's nothing wrong with it... But it performs frivolou
>fflush's and other things when all you want to do is end the program
>there. Why call another function when all you want is to end the pro
>;)
for the following C++ program
-- example.cpp
#include <iostream.h>
#include <stdlib.h>
class foo
{
public:
foo()
{
cout<<"Important init. code"<<endl;
}
~foo()
{
cout<<"Important end code"<<endl;
}
};
int main()
{
foo bar;
cout<<"Running..."<<endl;
return 0;
}
--end example.cpp
the results are:
Important init. code
Running...
Important end code
but if main in the above program is changed to
int main()
{
foo bar;
cout<<"Running..."<<endl;
exit(0);
return 0;//Note no warning on this line in BC4.5
}
the results are
Important init. code
Running...
And the important end code is not called!
There sure is something wrong with this. This code could be needed
to release hooked interrupts or other hardware (such as the video) which
could cause BIG problems after the program finishes.
If it is only memory that is not freed (or deleted) then it should get
cleaned
up but it sure is nicer if the correct code is executed.
Newbs
--
My .sig is in the FAQ
- Raw text -