🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #1525

Help requested: Something about pointers still eludes me

#1525
From: Lloyd P. Goldwasser
Date: Thu, 15 Oct 1992 18:12
53 lines
1901 bytes
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., ...}, {...}, {...} };

but everything I try crashes, even when it compiles.
I declare x_init and x differently because I want to be use x_init, a
pre-existing 2-dim array as a default to which x may initially point,
but I also want to be able to re-allocate x and put something else into
it as appropriate.
(I'm using the Numerical Recipes in C routines,

  x = matrix(m,n,o,p);
  free_matrix(x,m,n,o,p);

to re-allocate and de-allocate x.)


Here's this part of my program:


#import<stdio.h>

  float x_init[][7] =
    { {0.64, 0.13, 3.99, 1.49, 4.6, 4.94, 2.37},
      {1.31, 0.34, 3.07, 0.09, 0.43, 0.56, 1.1},
      {0.64, 0.11, 0.23, 5.59, 2.01, 2.63, 0.68} };
  float **x;

void main()
{
  printf("x_init[0][2] is %f\n", x_init[0][2]);    /* just checking */

  x[0] = x_init[0];             /* or x[0] = &x_init[0][0]; or ...  */

  printf("x[0][2] is %f\n", x[0][2]);        /* never gets this far */
}


I've tried what seems like every combination of *, &, and [] that I
can come up with, but to no avail.  The apparently analogous 1-d
pointer assignments work fine.  I'm not sure whether this is a
pointer thing, a 2-d thing, a NeXT thing, or what.  Or am I just
trying to do something wrong?


Thanks in advance,

Lloyd Goldwasser
goldly@u.washington.edu
Technical Details
Message-ID: <1992Oct15.181252.1796@u.washington.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!rpi!usenet.coe.montana.edu!news.u.washington.edu!news

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!rpi!usenet.coe.montana.edu!news.u.washington.edu!news
From: goldly@u.washington.edu (Lloyd P. Goldwasser)
Subject: Help requested: Something about pointers still eludes me
Message-ID: <1992Oct15.181252.1796@u.washington.edu>
Sender: news@u.washington.edu (USENET News System)
Organization: University of Washington
Date: Thu, 15 Oct 1992 18:12:52 GMT
Lines: 53