Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!texbell!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.lang.misc Subject: Re: Pointers as 3-tuples (Re: JLG's flogging of horses (was Re: Relationship between C and C++)) Message-ID: Date: 10 Apr 90 21:14:01 GMT References: <1BT2FU7ggpc2@ficc.uu.net> <14316@lambda.UUCP> <6529@brazos.Rice.edu> Reply-To: peter@ficc.uu.net (Peter da Silva) Organization: Xenix Support, FICC Lines: 42 In article <6529@brazos.Rice.edu> preston@titan.rice.edu (Preston Briggs) writes: > Ah. Then pointers are not more general than arrays :-) Not if you can allocate new arrays at will, and reference them somehow in a consistent manner. > > By making a > >pointer a 3-tuple (low, current, high) it is subject to the same bounds > >checking. > And why not be practical? Implementing pointers with triples!? > Going to be hard to keep in a register. Going to be hard to cast > into a long int and back. Doctor! Doctor! It hurts when I do this! So don't do this. Casting pointers to long ints and back is inherently dangerous. There is no guarantee that you can put a pointer in a register (you can't on an 80{,2}86 in large model), nor that you can put it in a long int (you can't on most word-addressed machines), so don't do it. The world is not a VAX. > With enough work by the compiler, the penalty for array bounds checking > can be reduced to less than 10% on systems code (hearsay, from > Peter Markstein) and much less on scientific code (Optimization of > Range Checking, Vicky Markstein, John Cocke, Peter Markstein). > Care to speculate on the cost of a 3-tuple scheme for pointers? About the same as the costs of bounds-checking on arrays passed to functions. About the same as the costs of bounds-checking on locally declared and allocated arrays. The only place it's going to cost more is when you use pointers for things arrays just can't be used for, such as lists. If you're doing scientific stuff, 3-tuple pointers and arrays are isomorphic. And if your code is worth a damn you're checking those pointers anyway. [ if(p == NULL) return FAILURE; ] Doesn't it make sense to let the compiler do this check where it can optimise it more effectively? -- _--_|\ `-_-' Peter da Silva. +1 713 274 5180. . / \ 'U` \_.--._/ v