Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!amelia!lemming.nas.nasa.gov!fouts
From: fouts@lemming.nas.nasa.gov.nas.nasa.gov (Marty Fouts)
Newsgroups: comp.lang.fortran
Subject: Re: Arrays and pointers
Message-ID: <1030@amelia.nas.nasa.gov>
Date: 21 Sep 88 18:44:43 GMT
References: <447@quintus.UUCP> <3826@lanl.gov> <1023@amelia.nas.nasa.gov> <15269@ames.arc.nasa.gov>
Sender: news@amelia.nas.nasa.gov
Reply-To: fouts@lemming.nas.nasa.gov.nas.nasa.gov (Marty Fouts)
Lines: 70

In article <15269@ames.arc.nasa.gov> lamaster@ames.arc.nasa.gov.UUCP (Hugh LaMaster) writes:
>
>You lost me here.  Arrays are a particular type of data structure.  They
>are no different from any other type of data structure.  So, if I
>generalize your argument, you could say "any data structure is a
>compact mechanism for annotating a mapping from names to addresses."
>Taken to an extreme, I don't need data structures at all, just pointers
>and memory cells.  Which is true, but...
>

I haven't lost you.  That's exactly my point.  Now add to it the
notational convenience of using pointers when they make the code
clearer to read then array references.  All programming can be done
with a Turing machine, but we go for notational convenience

>Portability always suffers when you drag in raw memory.  Contrary to
>popular belief, not all machines are byte addressable, and not all
>byte addressable machines allow arbitrary alignment.  In fact, not all
>machines have a single contiguous address space.  For all of these
>reasons, old Fortran programmers prefer to use pointers ONLY for passing
>the address of a data structure around, and not for other things.
>

Yes, you can write bad code with pointers.  That's not my point.  I
have never said to use *raw memory addresses*.  I haven't mentioned
byte addressing either.  Nor have I mentioned 'a single contiguous
address space.'  *NONE* of these things are relevant to the correct
use of pointers in addressing arrays.  Pointer arithmetic is done in
"thing" sized units, and it doesn't matter if the thing is 1/8 of a
word, 1 word, or N words long.  If you don't misuse pointers, you
don't see the underlying addressing mode.  Also, in this context,
pointers are used to address that part of memory which is a contiguous
address space --- After all, we are talking about pointers into
Fortran style arrays, which are contiguous.  Not a single such
address space, but many, one for each array.

Don't generalize about old Fortran programmers.  I am an old Fortran
programmer, having written my first "High Level Language" code for an
IBM 1620 and having written > 100K lines of Fortran; some
of which was ported to many machines.  I use pointers for all kinds of
name aliasing, all of the time.

>I have not seen anyone in this group suggest abolishing pointers.  In fact,

The context of 'expressive power' in the above was not abolishing
pointers, it was abolishing the expression of pointer
arithmetic/array naming equivalence in a programming language, which
has been espoused in this list.

>it turns out that many Fortrans have pointers, as some people were
>boasting.  The argument is whether pointers should be used for anything
>fancier than as a pointer to a data structure.  I suggest that, from the
>point of view of project management, other uses of pointers should be
>treated like assembly language code:  OK, if you have to, but, confine it
>to a small number of replaceable modules.
>

You are thinking of how to misuse pointers.  I am thinking of how to
correctly use them.  Even Wirth, that bastion of safe-code, thought
that pointers were tame enough for Pascal and Modula-2.  I can write
unmaintainable code using any facility (remember the GOTO debate and
how the first round was finally ended by Knuth's well reasoned when
to/ when not to paper?) or I can write elegant code, using any
facility.

+-+-+-+     I don't know who I am, why should you?     +-+-+-+
   |        fouts@lemming.nas.nasa.gov                    |
   |        ...!ames!orville!fouts                        |
   |        Never attribute to malice what can be         |
+-+-+-+     explained by incompetence.                 +-+-+-+