The importance of showing ALL of the code in C

From: Fred Cisin <cisin_at_xenosoft.com>
Date: Wed Feb 6 16:23:52 2002

On Wed, 6 Feb 2002, John Chris Wren wrote:
> Perhaps I worded that poorly. I know that we vould index it by 666, if we
> like, but it's liable to generate a runtime error (one a machine with a MMU,
> at any rate. A non-MMU processor the effects might never show up. Or you
> may tell the CP/M BIOS that your disk has 10 heads instead of 2).

With, OR WITHOUT, an MMU, it is legal C code!
  int A[10];
  int N;
. . .
  A[10] = 0;
will NOT generate a runtime error.
"If you want to shoot yourself in the foot, C provides you with unlimited
ammunition."
Depending on memory model, we could overwrite other parts of our data, and
parts of THAT could be disastrous (such as following that by dividing
something by N).

With certain memory models, and with an ubelievably badly written OS, it
might be possible to step on memory that doesn't even belong to the
program. Then we could, indeed bluescreen it.

> I was thinking "legal" as in "I'm not so stupid as to permit this to
> happen."
 
C accepts as "legal" LOTS of stuff that we hopefully would not be so
stupid as to permit to happen. And there are some professional
programmers who will do stuff like that! "By the time that we use A[10],
we no longer need N, so we just let it become an extension of the array"!


But many other languages will permit "legal" language structures that are
suicidally stupid, such as:
  X = 0
  Y = Z / X

--
Grumpy Ol' Fred        cisin_at_xenosoft.com
Received on Wed Feb 06 2002 - 16:23:52 GMT

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:34:44 BST