Re: unexpected result



Richard G. Riley schrieb:
On 2006-03-12, Richard Heathfield <invalid@xxxxxxxxxxxxxxx> wrote:
jaysome said:

<snip>

<dialogue>
Son: "Dad, I want to learn how to program in C."

Dad: "Son, although I admire your goal, I've been reading a lot in CLC
lately, and based on what they're saying in there, I'm pretty shocked
about how a simple, honest mistake you might make could lead to
formatting my hard drive. So I have to say no on this one."

In 1989, I was learning C. The guy sitting next to me was learning C too. He omitted to provide sufficient storage for a string. (He was just one byte short.) When the program ran, he saw pretty much what he expected to see, just general student-program output, you know the stuff - and then, at the bottom there, it said something like:

"Do you really want to format C: (Y/N)?"

He was *very* fortunate. The result of this particular instance of undefined behaviour appears to have been a jump into "the system" - and if it had jumped just a bit further, he could well have had his hard drive formatted without being asked. No, I'm not making this up.

Yes you are :) Scare mongerer you ... Sounds more like you modified
his program to make him pap his kecks ...

That seems to be an unfair accusation.

It was clearly a PC then? DOS?

The following year, I'd managed to find a job as a C programmer. A colleague of mine had clearly been on the Intermediate C course and the Advanced C course, but had unaccountably failed to turn up for the Basic C course. He made *exactly the same error* (i.e. an array that was one byte too short for the string being stored there), and this time it did actually trash the machine, to the extent that it wouldn't even boot until we started feeding diagnostic diskettes into it.

If he had done an advanced C course and an Intermediate C course then
he presumably knew about buffer issues in C. It is impossible that he
didnt or his intermediate and his advanced programs would have failed too.

Considering the people with which I had the dubious pleasure
to be at the receiving end of a job interview... Many had
excellent references and shiny documents proving their excellence
but were stumped after a couple of intermediate level questions.
When going back to basic level questions, I still found enough
gaps in their knowledge. From my point of view, passing an
advanced or better level course only means that the person should
know about such things but not that he or she actually does.

Good C programmers frequently get the count wrong on array traversal :
and it doesnt cause your hard disk to get erased. All programmers are
human.

Well, in 99.99999999999999% of the cases. The old "n-1" will haunt C
programmers for years no matter good : its experience which means we
avoid it most of the time.

(Oh and did I mention a good debugger would catch it too ..)

And electric fence or valgrind could catch even the ones you
did not expect.

Your "Dad" character is quite right. Leave C well alone unless you're prepared to spend the time and effort it takes to get it right.

Alternatively, jump in there with a good book and have a lot fun
learning the language. If you worried that your hard disk would melt
for every out of control memory access you have in C then trust me, C
would be history by now.

That is true; however, I once upon a time managed to kill
80 percent of a harddisk's contents by an off-by-one error
when writing a Copper list. And it was not much fun to
bring it back floppy disk by floppy disk (as far as possible).

I did not follow it through but essentially missing memory
protection made it possible for the computer to run off wildly
through memory unfortunately encountering only legal opcodes
until most of the harddisk sectors contained only rubbish
while I thought that I should have given the task a higher
priority and why is the harddisk LED glowing...


Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
.



Relevant Pages

  • Re: unexpected result
    ... Dad: "Son, although I admire your goal, I've been reading a lot in CLC ... The guy sitting next to me was learning C too. ... and it doesnt cause your hard disk to get erased. ...
    (comp.lang.c)
  • Re: noise as a snore in memory when computer is in idle
    ... | snore sound when you closed it without a disk in it. ... | memory which is most often used for RAM-type memory (or flash memory ... Go to the hard disk manufacturer's web site and download their diagnostic software ...
    (microsoft.public.security.virus)
  • Re: adding memory question
    ... performance increase from the memory upgrade. ... free space is not very much for windows and possibly part of your overall ... If I need more memory AND more hard drive, that might really be the time ... think that your money would be far better spent on a hard disk ...
    (alt.sys.pc-clone.dell)
  • Re: "Never change a running system"
    ... > Probably due to some internal memory conflict... ... If the temporary files were corrupted in the ... > even the stuff which was in My Documents had been lost. ... > preferably not in My Documents, but on the hard disk which (can be accessed ...
    (sci.lang)
  • Re: Delphi - desktop, Web, or USB?
    ... A few days ago I was ordering a new compact Dell, and was tempted to order a USB memory stick with the capacity of 8 GB. ... What I really want to carry is the contents of the hard disk, not the hardware needed to access the hard disk. ... Having all the software on a USB stick together with the corresponding data reduces what I have to carry to something I can carry in the same pocket as the loose change. ... -- A typographical system like LaTex with at good editor, the ideal would be something like WinEdt which also handles R. ...
    (borland.public.delphi.non-technical)