Article View: comp.lang.misc
Article #31Re: Pointers
From: John Haxby
Date: Tue, 03 Nov 1992 13:06
Date: Tue, 03 Nov 1992 13:06
69 lines
4315 bytes
4315 bytes
In article <Bx3BsH.I0J@mentor.cc.purdue.edu>, hrubin@pop.stat.purdue.edu (Herman Rubin) writes: |> In article <1992Nov2.083810.1652@syacus.acus.oz.au> ian@syacus.acus.oz.au (Ian Joyner) writes: |> >jch@rdg.dec.com (John Haxby) writes: |> |> >>C's pointers are a pain in the neck sometimes. |> |> >Great understatement :-) You simply don't need C style pointers in decent |> >programming languages. Standard Algol 60 does not have pointers. However, |> >I use pointers in Algol all the time, Unisys A Series extended Algol 60 |> >that is (the assembler for the machine.) These pointers are very different |> >in nature to C pointers. They are mainly meant for scanning text and data |> >strings. These are very useful for parsing, etc, and map into single |> >machine instructions, so that you can accomplish quite complex block |> >updates with editing in one instuction. |> |> I disagree. It is not too usual that I think C has done anything fairly |> well, but its general use of pointers (not the whole syntax, etc.) IS |> fairly close to what I believe pointers should be. A C pointer contains |> the address of something, and I may want this something to be the address |> of an integer, the address of a float, the address of a subroutine, the |> address of another pointer, the address of something which even may have |> different uses at different times. C's pointers don't actually provide anything useful, apart from, perhaps, an ability to duplicate Lindsay's `triple ref' code. If one thinks in terms of references to objects and elements of arrays rather than pointers to both, things become somewhat clearer. C's pointers-as-references are not all that different from Algol68's except in syntax and an explicit `address-of' operator. Where you do get some significant differences is in arrays and storage management. Algol68 is still way ahead of C in this game. Array members and references may compile to much the same code, but in the language they are treated quite differently. The need for pointer arithmetic (that C provides) simply does not arise (getting rid of a whole series of bugs that dog C programs in one swell foop). The distinction also helps the garbage collector find references to objects: in C an array may be referenced by a pointer to some element in the middle rather than by a base pointer which makes the GC's life harder than is strictly necessary (well, ok, impossible). The distinction can also be used for array bounds checking (useful for eliminating another series of bugs). Of course, the usual argument about array bounds checking is that is significantly adds to the cost of a store or fetch. However, compile-time optimizations can remove a good deal of the checking and run time checking is often so tightly bound into the pointer arithmetic that the check takes little extra time. In a language with exceptions, you may find that there is no extra code at all for many cases, eg while true do sum := sum + x [i] i := i+1 end except when bounds: end Generates no extra code for the bounds checking. The cases where the bounds checking finds bugs in the program, before the bug tramples over all the outlying data, are, of course, immensely valuable. Yes, I know about the various tools for checking for this sort of thing, but if I learn to swim with armbands, does that mean I can forsake them and swim to France? (to paraphrase Dijkstra, I think). -- John Haxby, Definitively Wrong. Digital <jch@rdg.dec.com> Reading, England <...!uknet!wessex!jch> ---------------------------------------------------------------- The opinions expressed herein are my own, not my employers.
Technical Details
Message-ID:
<1992Nov3.130634.26112@rdg.dec.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!pa.dec.com!rdg.dec.com!jchReferences:
<chl.720269838@cs.man.ac.uk> <1992Oct29.113733.3956@rdg.dec.com> <1992Nov2.083810.1652@syacus.acus.oz.au> <Bx3BsH.I0J@mentor.cc.purdue.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.misc Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!pa.dec.com!rdg.dec.com!jch From: jch@rdg.dec.com (John Haxby) Subject: Re: Pointers Message-ID: <1992Nov3.130634.26112@rdg.dec.com> Sender: news@rdg.dec.com (Mr News) Organization: Digital Equipment Corporation References: <chl.720269838@cs.man.ac.uk> <1992Oct29.113733.3956@rdg.dec.com> <1992Nov2.083810.1652@syacus.acus.oz.au> <Bx3BsH.I0J@mentor.cc.purdue.edu> Date: Tue, 3 Nov 1992 13:06:34 GMT Lines: 69