Re: C++ Question: Crashing C++
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sat, 18 Apr 2009 16:52:54 -0400
The problem is that the word "crash" is a meaningless noise word. It is used to represent
"Any condition that causes program termination". Newbie developers use it to describe
assertion failures, access faults, stack overflow, stack overrun, memory corruption, etc.
Calling abort() would, of course, mean the program was badly implemented. It has the same
value as calling exit() explicitly: only newbies make those mistakes, because the concept
that the user and the user alone owns the right to terminate the program escapes them. A
professor once showed them that if their program is confused they should call exit() to
terminate the program, which is fine for a 20-line toy classroom example, but doesn't
survive the test of reality. No real program should ever call exit() explicitly.
The worst database library in the known universe was written by some children whose idea
of what to do when they detected some inconsistency in the data was one of the following:
::MessageBox(NULL, ...);
or
::MessageBox(NULL, ...);
exit(1);
or
exit(1);
In the first case, they didn't return an error code to the caller, just popped up a
message box behind the app. Since its parent was the desktop, it didn't disable the
parent window, so you could keep doing things.
In the second case, the program would terminate. Never mind you would lose all your
updates, your context, everything you were working on; that mattered not to these twits.
Something was wrong, and they HAD to exit (because someone had once told them that if your
program is messed up, you have to exit it immediately!)
In the third case, the program just disappeared with no hint as to what went wrong.
Note that sometimes these could occur because of bad parameter values from the caller;
instead of returning "bad parameter" they would exit the program! Talk about
worst-possible-examples of code, they had it.
I tried to fix it, but their code was so bad that there was no way to actually repair the
damage. We stopped using their product.
So the question is, what is meant by "crash"? Without having a clue as to what this
nonsense word means, there is no way to suggest any possible solution, other than the ones
I've already suggested (good checking of API calls and pointer validity checks).
joe
On Sat, 18 Apr 2009 03:04:47 -0500, "Scot T Brennecke" <ScotB@xxxxxxxxxxxxxxxxxx> wrote:
How about simply calling the CRT function abort() ? Wouldn't that qualify as a crash?Joseph M. Newcomer [MVP]
<steph.mcsams@xxxxxxxxx> wrote in message
news:d5aa1224-cfe2-476b-9789-a6adc0528775@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I was asked this question in an interviewer some time back, the
question was...
"what is a guranteed way to crash a c++ program?"
It was an open-ended question, let me know what you think.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- C++ Question: Crashing C++
- From: steph . mcsams
- Re: C++ Question: Crashing C++
- From: Scot T Brennecke
- C++ Question: Crashing C++
- Prev by Date: Re: Interview Questions
- Next by Date: Re: Latest utility programs: NUMA
- Previous by thread: Re: C++ Question: Crashing C++
- Next by thread: CScrollbar
- Index(es):
Relevant Pages
|