Path: utzoo!attcan!uunet!cs.utexas.edu!rice!titan!preston From: preston@titan.rice.edu (Preston Briggs) 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: <6529@brazos.Rice.edu> Date: 10 Apr 90 17:14:10 GMT References: <1BT2FU7ggpc2@ficc.uu.net> <14316@lambda.UUCP> Sender: root@rice.edu Organization: Rice University, Houston Lines: 45 In article peter@ficc.uu.net (Peter da Silva) writes: >In article <14316@lambda.UUCP> jlg@lambda.UUCP (Jim Giles) writes: >> Pointers are more general than arrays in that they are free from bounds >> checking and allow arbitrary aliasing. > >The first statement here is false, as I have demonstrated. Ah. Then pointers are not more general than arrays :-) > 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. 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? If not, can we dispose of them as a topic? >The second statement is irrelevant, because arrays can also be >arbitrarily aliased. Fortran sidesteps this problem by declaring that this >aliasing is illegal, but really doesn't provide a mechanism for ensuring >that no illegal aliasing is going on. Arrays in fortran can be aliased at procedure calls (illegally) and in equivalence statements (legally). Equivalence statements are easy. Calls are more difficult but can be handled correctly, even allowing for separate compilation. That is, it's possible to detect the aliases at compile-time and either complain or handle them correctly (but with less efficient code). Aliasing due to pointers can be introduced at any assignment. It's possible to detect aliasing, but the analysis is either very imprecise or very expensive or both. By imprecise, I mean overly conservative -- pointers will appear to point to many places. -- Preston Briggs looking for the great leap forward preston@titan.rice.edu