When it is amoral... (Re: When is a cast not a cast?)

Blair P. Houghton bph at buengc.BU.EDU
Thu May 4 08:37:14 AEST 1989


			   Hey!  That's me!! :-) --vvvvvvvvvvvvvvvvv
In article <2747 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
>
[...You've read the movie, now go see the book!!...]

Thanks to all who pushed me upright.  I seem to have been tottering on
the brink of looneytunes for the past few days (pulling ten all-nighters
in 2.5 weeks is no way to live, especially when yer a grad stoont and
don't have to put up with that final-exam shit anymore.  Yup.  I go
40hrs sleepless because I _want_to_... %-|)

Anyway, it's now well established that I've harbored a fundamental
misconception about C and pointer indexing for a number of years.

I think I've got it identified, and I hope someone else benefits from
my story.  In Jim Kingdon's emailed reply to my original posting, he
mentioned that I should be wary of scaling in pointer arithmetic.  I
wrote back:

	I know all about the automatic scaling of an integer in
	pointer arithmetic.

	I've just always felt a little guilty about using what I'd
	interpreted to be a convenience.  Rather than a proper
	feature of the C syntax, I'd always felt that adding an
	integer to a pointer was allowed as being "the obvious
	thing that should be done in that situation."  There are
	lots of 'obvious' things that are _not_ implemented that
	way, however, and that should have been a clue.  Still, I
	just took it for granted that what was going on was a
	promotion from integer to pointer, then the addition.

	Now I know much, much better.  A pointer isn't really a
	data type at all.  It's a different sort of beastie,
	germane only within a program, and therefore it is
	fallacious to see it as having the properties of a
	countable, measurable, or otherwise physical entity.

The way pointers work implies that they don't refer at all to
anything physical, even to memory locations.

It doesn't change the fact that I'd like to be able to add and subtract
pointers regardless of what trouble I _might_ get into.  Considering the
general level of danger incurred by programming in something so potentially
obfuscatory as C, it's a small barrier to remove.  The arguments of
"why would you want to do _that_?" don't hold water.  I counter with
"Why would you want variadic functions?" and "Why would you want to
define mathematical routines when you can write your own in assembler
and link to them?"

				--Blair
				  "And one of these days I'll know what
				   the middle pedal on a piano is for."



More information about the Comp.lang.c mailing list