how do i terminate a program in the middle of it with out any error messages?....
how do i terminate a program in the middle of it with out any error messages?....
exit(0)?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
That's the one; but sometimes that is a bad idea. Why would you be doing this termination?
"If you tell the truth, you don't have to remember anything"
-Mark Twain
return 1.
and why would this be a bad idea ? isnt the purpose of the exit() function to cause immediate normal termination of a program ? just wondering
That's the one; but sometimes that is a bad idea. Why would you be doing this termination?
That only returns from the currently executing function--it does not terminate the program. Additionally, you would typically return 0 when there are no errors, just like in main():Originally Posted by indigo0086
Code:int main() { //code return 0; }
Several reasons:Originally Posted by C of Green
- Calling exit will not give the caller a chance to deal with the problem. Exceptions are better.
- Calling from inside an object destructor may originate an infinite recursion.
- Calling exit does not guarantee all resources get released. Namely, local variables of the calling function will not have their destructors called.
return does not terminate a process unless from within main. Also, the argument value 1 will indicate an error.Originally Posted by indigo086
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
oh...
Program designs vary widely, but in general, when a program exits without error, it is because main()'s return was reached logically. If there's an error that can be resolved only by program termination, then throw an exception and, should you find the problem truly is unresolvable at every level of calling, the program will be terminated.
"If you tell the truth, you don't have to remember anything"
-Mark Twain