🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #1170

Re: Pointers as 3-tuples (Re: JLG's flogging of horses (was Re: Relationship between C and C++))

#1170
From: Jim Giles
Date: Tue, 10 Apr 1990 22:00
89 lines
4276 bytes
From article <S4U2APBggpc2@ficc.uu.net>, by peter@ficc.uu.net (Peter da Silva):
> 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.  [...]

You have 'demonstrated' no such thing.  You have proposed an implementation
which would _make_ my first statement false.  You have asserted (perhaps
correctly) that the new C standard actually supports your interpretation.
However, you have _NOT_ demonstrated that pointers which obey bounds are
more general that arrays (they aren't).  You have _NOT_ demonstrated that
pointers  _should_ obey bounds.

In fact, what you are recommending is a constraint on pointers which
removes one of the _only_ features that I thought pointers were useful
for.  I already had a pretty low opinion about the value of pointers
and you are busy destroying what respect I had left.  If it is your
intent to make pointers seem _less_ useful than they might be, you
are succeeding.

> [...]
>> Arrays are more general than
>> pointers in that they can be multiply dimensioned.
> 
> The C semantics of multiply dimensioned arrays as arrays of arrays
> demonstrates the opposite.

How does a misinterpretation of the semantic properties of multi-
dimensional arrays demonstrate anything but that C has not been
well designed for array manipulation?  Multidimensional arrays
are NOT arrays-of-arrays.  The subscripts of a multidimensional
array are independent and carry _equal_ weight.  There are no
'master' dimensions to which the others are 'slaves'.  The user of
multidimensional arrays should seldom have to know whether arrays
are stored row- or column-wise (he should _care_ about this difference
even less often).  C forces such irrelevant distinctions into every
context where multidimensional arrays are used: as args to procedures,
the user must provide for the array indexing calculation itself
by manual means.

> [...]
>> Pointers are only isomorphic to _one_dimensional_arrays_, and only if
>> their aliasing and freedom from bounds are both curtailed.
> 
> The first statement is false, because C semantics treats pointers as
> multiply dimensioned arrays (given a proper declaration), [...]

Oh!  Gee, I was unaware of that.  Please enlighten me as to the proper
declaration for the following case:

main(){
       int A[10][20];
       ...
       sub1(A);
       ...
}
       sub1(pa)
       ...      /* somewhere here there should be a declaration
                   which allows me to treat pa as a multiply dimensioned
                   array.  I hope you can show it to me.  Everyone
                   else claims that I have to declare a macro to do the
                   subscript calculation (or, shudder, do the calculation
                   by hand).  */
{...}

Actually, of course, C has no way of doing this.  The procedure can't
find out the dimensions of the argument.  And even if I were to pass
the values 10 and 20 as separate arguments, the C declaration rules
would not permit me to declare 'pa' as "int pa[bnd1][bnd2]".

No, 'pa' is isomorphic to a one-dimensional array with bound 10*20==200.
You can move 'pa' around linearly by adding and subtracting to it, but
you can _never_ double subscript it.

> [...]                                               and the second
> statement is only true for programs that are broken in any case... just
> like Fortran programs where you do something like:
> 
> 	INTEGER A(10)
> 
> 	CALL PROC(A,A)

Not necessarily broken.  Only if PROC modifies one or more of its
arguments.  Many C programs which do this sort of thing also turn
out to be buggy.  That's why you don't lose much by making it
illegal.

J. Giles
Technical Details
Message-ID: <14327@lambda.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!lanl!lambda!jlg
References: <S4U2APBggpc2@ficc.uu.net>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!lanl!lambda!jlg
From: jlg@lambda.UUCP (Jim Giles)
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: <14327@lambda.UUCP>
Date: 10 Apr 90 22:00:12 GMT
References: <S4U2APBggpc2@ficc.uu.net>
Lines: 89