Article View: comp.sys.next.programmer
Article #1549Re: Help requested: Something about pointers still eludes me
From: Sean Lamont
Date: Fri, 16 Oct 1992 04:28
Date: Fri, 16 Oct 1992 04:28
34 lines
1926 bytes
1926 bytes
In article <1992Oct15.181252.1796@u.washington.edu> goldly@u.washington.edu (Lloyd P. Goldwasser) writes:
>I'm trying to make a dynamically-declared pointer pointer
>
> float **x
>
>point to a pre-existing 2-d array
>
> float x_init[][7]={ {1., 2., 3., ...}, {...}, {...} };
>
I believe the fundamental problem here is your misunderstanding of
2-d arrays vs. arrays of arrays (ptrs to ptrs).you've declared two things here, one
static array of constants, and one "pointer pointer". While you can
refer to both of them as array[posx][posy], the static declaration is a
2-d array, which is NOT an array of pointers. It is one pointer into a
chunk of memory which contains the following
First row
Second row
...
Nth row.
There's only one level of indirection here. However, the float ** is
two levels of indirection.
If you really want to do what you ask, you can't do it with a simple
assign. What you would probably need to do is malloc space for the
primary array, and assign (in a loop of some sort) each secondary
pointer to point at &x_init[i]
--
Sean T. Lamont | "Don't oppress me, It's
zeno@genetics.washington.edu | 'computer of color!' "
lamont@abstractsoft.com |_______________________________
Abstract Software
Technical Details
Message-ID:
<1992Oct16.042851.14939@u.washington.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!ogicse!news.u.washington.edu!phylo.genetics.washington.edu!zenoReferences:
<1992Oct15.181252.1796@u.washington.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!news.u.washington.edu!phylo.genetics.washington.edu!zeno From: zeno@phylo.genetics.washington.edu (Sean Lamont) Newsgroups: comp.sys.next.programmer Subject: Re: Help requested: Something about pointers still eludes me Message-ID: <1992Oct16.042851.14939@u.washington.edu> Date: 16 Oct 92 04:28:51 GMT Article-I.D.: u.1992Oct16.042851.14939 References: <1992Oct15.181252.1796@u.washington.edu> Sender: news@u.washington.edu (USENET News System) Organization: University of Washington, Seattle Lines: 34