Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!ucsd!orion.oac.uci.edu!cerritos.edu!arizona.edu!arizona!gudeman From: gudeman@cs.arizona.edu (David Gudeman) Newsgroups: comp.lang.misc Subject: Re: C's sins of commission Message-ID: <26296@megaron.cs.arizona.edu> Date: 12 Oct 90 01:11:24 GMT Organization: U of Arizona CS Dept, Tucson Lines: 44 In article <65409@lanl.gov> jlg@lanl.gov (Jim Giles) writes: ] ]A pointer, on the other hand, is a variable whose _value_ is an ]address... But, addresses ]aren't particularly important to me. I almost never need to know ]or manipulate them in any way. So, why do I need a data type who's ]values are addresses? An int, on the other hand, is a variable whose _value_ is a bit-string. But, bit-strings aren't particularly important to me. I almost never need to know or manipulate them in any way. So why do I need a data type who's values are bit-strings? The above probably won't make the point (though it should) so I will expand on it. A pointer might have an address as its concrete value, but you should be thinking of a pointer as an abstraction, not by its concrete representation. A pointer is a data type with certain operations on it: for pointers declared "TYPE *p, *q", the following *p returns an l-value referencing an object of type TYPE (as for any other data object, if p is not initialized the outcome of any operation is undefined) p + i returns a pointer to the ith element of type TYPE following *p. This is only valid if there is a contiguous sequence of at least i elements of type TYPE following *p. p < q returns TRUE iff *p preceeds *q in a sequence of elements of type TYPE, assuming that both *p and *q are members of the same contiguous sequence. etc. There is no need to refer to addresses. Pointers are no less abstract than arrays. There is no guarantee that "p + i" will return an address "i*sizeof(TYPE)" greater than that of *p, anymore than it is guaranteed that the address of A[i] is "(i-j)*sizeof(TYPE)" more than the address of A[j]. I know implementations of both arrays and pointers where these conditions do _not_ hold. -- David Gudeman Department of Computer Science The University of Arizona gudeman@cs.arizona.edu Tucson, AZ 85721 noao!arizona!gudeman