inclusive-lower-bound, exclusive-upper-bound (was Re: Range Operation pre-PEP)

greg jorgensen greg at C800000-A.potlnd1.or.home.com
Thu May 17 05:06:35 EDT 2001


On Mon, 14 May 2001, Andrew Maizels wrote:

> David LeBlanc wrote:
> ...
> No; after all, you have to use pointers at some level.  And C's arrays
> and strings (which are just arrays, which are just pointers) aren't bad
> if you're programming at a low level.
>
> Start using it to write applications and it's Memory Violation time and
> Buffer Overflow Exploit of the Month Club.

Since you're designing your own language I'm going to get a little
pedantic on you.

Arrays and pointers are NOT the same in C. In fact a lot of the problems
people have writing working C code are caused by confusing the two things.

* Pointers are modifiable l-values, array names are not.

* The address of an array is known at compile time, but the value of a
pointer is not known until run time. The compiler does not need to
generate indirection code for an array.

* An array definition implicitly allocates memory for the array elements.
A pointer definition/declaration does not allocate any memory.

* A pointer can be null, invalid, or pointing at the wrong place. An array
name cannot.

C (by design) treats array names as a pointer to the first element of
the array in some contexts for convenience, but that is syntatic sugar,
not an equivalence.

I've written a lot of C code over the last 20 years and I have never had
memory management problems so severe that I faulted the language. I
certainly prefer Python in a lot of circumstances--and I don't miss
explicit memory management when I use Python--but I don't think C is
deeply flawed because it makes me pay attention to how I allocate,
reference, and deallocate memory.

> Yes, it can (and has) been made to work.  But it's not much fun.

That's an understatement. The installed base of working C code is vast,
and C is among a handful of languages still in use thirty years after it
was first implemented. As for fun, well, that's a matter of taste. I like
C, and I like Python. They are complementary tools, both well-designed and
expressive.

Another common misstatement about C that you repeated is "C is too
low-level." Considering that C has been ported to practically every
computer architecture ever devised, I think the language is a bit higher
level than it gets credit for. Sure, C's data types map directly to
"natural" structures on the host platform, but why is that a bad thing? In
fact for the kinds of programming C is best for, that kind of closeness to
the underlying architecture is what you want.

Greg Jorgensen
Portland, Oregon, USA
gregj at pobox.com





More information about the Python-list mailing list