Path: 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: <14342@lambda.UUCP> Date: 12 Apr 90 03:17:15 GMT References: <7=U2P58xds13@ficc.uu.net> Lines: 46 From article <7=U2P58xds13@ficc.uu.net>, by peter@ficc.uu.net (Peter da Silva): > In article <14327@lambda.UUCP> jlg@lambda.UUCP (Jim Giles) writes: >> However, you have _NOT_ demonstrated that pointers which obey bounds are >> more general that arrays (they aren't). > > Fine. How do you implement dynamic storage with arrays? That's EXACTLY MY POINT!!! Pointers are for dynamic memory implementation (but, not necessarily visable to the user of the allocation mechanism). At least, that's the one application that I'm really certain that pointers should be used for. I can't think of many others. Pointers which obey bounds are worthless as dynamic memory implementors. The dynamic memory allocator is what _sets_ the bounds - be pretty silly to force it to obey them. > [...] >> 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). */ > > int (*pa)[10][20]; > > (*pa)[4][5]; Nope, Nope, Nope, .... how does the guy who wrote 'sub1' know that the array that will be passed has bounds 10 and 20? Answer: he doesn't. In fact, the routine might be called many times - with a differently bounded array each time. Keep looking! You may find the answer yet! J. Giles