Article View: comp.sys.next.programmer
Article #1568Re: Help requested: Something about pointers still eludes me: Still elusive
From: Lloyd P. Goldwasser
Date: Fri, 16 Oct 1992 23:02
Date: Fri, 16 Oct 1992 23:02
61 lines
2652 bytes
2652 bytes
Thanks to all who have responded either directly to me or to this
group about my question regarding pointers and arrays. They have
clarified this contrast for me and, maybe, others as well.
For better or worse, I suspect that there's still some light to be
shed. Several of the suggestions work on their own terms, but, alas,
haven't yet produced a solution for my purposes.
If all I want to do is make x point to x_init when I want it to, then
declarations like
float (*x)[7];
seem to be the way to go. However, my reason for using
float **x;
in the first place is that I'm using routines from Numerical Recipes
in C; they require this kind of declaration of x. These routines,
which I use constantly, allow me to allocate and de-allocate x on the
fly, with array bounds of my own choosing:
x = matrix(4,10,1,9);
gives me x[4][1] ... x[4][9] ... x[10][1] ... x[10][9]. Then I can
do
free_matrix(x,4,10,1,9);
x = matrix(0,6,12,20);
and get x[0][12] ... x[0][20] ... x[6][12] ... x[6][20], and so
forth. The "layer of pointers between my floats and x" is a price
that I'm willing to pay for this flexibility: these routines are so
transparent they are a pleasure to use.
But neither declaration above allows me to make the declaration and
assignment
float x_init = { {1., 2., ...}, {...}, ... {...} };
x = x_init;
without getting a compiler error (e.g., "warning: assignment between
incompatible pointer types"; other possibilities allow me to make the
assigment but give me type 5 errors when I do free_matrix(), or
worse). It makes sense to me now that the compiler complain about
the assignment, but that still doesn't make the assignment, if I can
accomplish it somehow, any less desirable.
I suppose that if I were more of a programmer I could write similarly
transparent routines of my own that would accomplish all goals at
once. Or is there still some other way to declare x that would
convince C that the assigment, or some equivalent, is really not so
unreasonable?
Ideas?
Thanks to all,
Lloyd Goldwasser
goldly@u.washington.edu
Technical Details
Message-ID:
<1992Oct16.230237.5877@u.washington.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!think.com!rpi!usenet.coe.montana.edu!news.u.washington.edu!newsReferences:
<1992Oct15.195147.3973@unmvax.cs.unm.edu>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: Re: Help requested: Something about pointers still eludes me: Still elusive Message-ID: <1992Oct16.230237.5877@u.washington.edu> Sender: news@u.washington.edu (USENET News System) Organization: University of Washington References: <1992Oct15.195147.3973@unmvax.cs.unm.edu> Date: Fri, 16 Oct 1992 23:02:37 GMT Lines: 61