Re: Strange programming problem
From: Mike Bartman (omni_at_foolie.omniphile.com)
Date: 08/21/03
- Next message: Larry Kilgallen: "Re: Strange programming problem"
- Previous message: Mike Bartman: "Re: Strange programming problem"
- In reply to: Ryan Moore: "Re: Strange programming problem"
- Next in thread: Bill Gunshannon: "Re: Strange programming problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 20 Aug 2003 21:10:26 -0400
On Wed, 20 Aug 2003 15:07:35 GMT, Ryan Moore
<rmoore@rmoore.dyndns.org> wrote:
>On Wed, 20 Aug 2003, Larry Kilgallen wrote:
>> From what I know of Cobol, it is quite amenable to range checking.
>> The use of null-terminated strings in C prevents such automatic
>> compiler safeguards.
>
>This is not necessarily true. Depending on how your array is allocated,
>the compiler can do range checking.
You can't really range-check in C, because it's possible to play with
array contents using pointers, rather than explicit array element
references. The end result is that you can overfill an array and
there's no way for the compiler to know about it. Even a runtime
check can be fooled unless you have a lot of support for memory
management and isolate the address spaces of each array so that
running off the end will trigger an invalid virtual address
reference...and even that won't work if you run far enough off the end
and end up in the next array over.
Think of it from the assembly language viewpoint...that's basically
what C is, from a protection standpoint. You can reference any part
of memory without limit using pointers, so you can screw up any part
of the program or its data. Pascal, for instance, limits this by not
allowing pointer arithemetic and not allowing cross-type pointers.
This can make writing certain kinds of code more difficult, but it
also protects you from some of the more hideous errors that C is prone
to.
If the PC industry had been able to settle on a language like Pascal
or Ada for most development, rather than C, we'd see far more reliable
systems than we see today. Saying that a good and careful programmer
can write solid code in C is true, but pointless. Most programmers
aren't all that good, and most aren't granted the time to be careful
by their management.
-- Mike Bartman
----------------------------------------------------------------
To reply via e-mail, remove the 'foolie.' from the address.
I'm getting sick of all the SPAM...
----------------------------------------------------------------
- Next message: Larry Kilgallen: "Re: Strange programming problem"
- Previous message: Mike Bartman: "Re: Strange programming problem"
- In reply to: Ryan Moore: "Re: Strange programming problem"
- Next in thread: Bill Gunshannon: "Re: Strange programming problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|