Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!mcsun!ukc!icdoc!inmos!mph@lion.inmos.co.uk From: mph@lion.inmos.co.uk (Mike Harrison) Newsgroups: comp.lang.misc Subject: Re: Relationship between C and C++ Message-ID: <4881@ganymede.inmos.co.uk> Date: 23 Mar 90 13:27:30 GMT References: <19253@megaron.cs.arizona.edu> Sender: news@inmos.co.uk Reply-To: mph@inmos.co.uk (Mike Harrison) Organization: INMOS Limited, Bristol, UK. Lines: 60 In article <19253@megaron.cs.arizona.edu> gudeman@cs.arizona.edu (David Gudeman) writes: > ... >It seems that most C pointer critics (like this one) are making the >assumption that pointers are used only to avoid inefficiency in array >indexing. Quite the contrary. I do a lot of C programming, and I >choose beteen the array abstraction and the pointer abstraction by >whichever fits the problem better. > >Pointers are just another form of abstraction, one that a lot of >people find quite useful and intuitive. Quite true, but for use of the abstraction you do not need an unrestricted ability to 'point' at any old thing! > ... I have seen several comments >that pointers are a "low-level" mechanism. This strikes me as a >content-free statement. Just how is "low-level" being defined? "Low level" in a way entirely analogous to that in which 'goto' is "low level". You can build loops and conditional structure by using 'skip' statements and 'goto' statements, but everyone would now agree (? :-) that (except perhaps for *very* special cases) it is far safer to use the "high level" abstractions such as 'if ... then ... else' or 'for ... loop' etc. Similarly you *can* build linked data structures by using pointers and an 'address-of' operator. The problem is not pointers per se, it is the unrestricted ability to build 'pointer values'. Most modern languages give you a 'reference' mechanism, either through a restricted (and relatively safe) kind of point (cf. Ada's access types) or by an even higher level abstraction such as the sequence, (in this case, for functional languages there will be a mechanism such as th Y [or recursive] combinator, some 'dressed up' version such as 'letrec' to let you build cyclic structures. Thus, I am not underestimating the power of pointers, just trying to show that the unrestrictedness of 'raw' C pointers is very rarely needed, and that restricted pointers are *far* safer. In fairness, I should quote one case where I found UNTYPED pointers made life much easier. This was in a software emulation of a Graph Reduction Machine, where items on a stack needed to refer (at different times) to different types of objects. I wrote this in C and had to 'fake' all pointer types. I actually found C 'too' strongly typed in this case :-). Mike, Michael P. Harrison - Software Group - Inmos Ltd. UK. ----------------------------------------------------------- UK : mph@inmos.co.uk with STANDARD_DISCLAIMERS; US : mph@inmos.com use STANDARD_DISCLAIMERS;