Mail Archives: djgpp/2000/04/30/08:52:26
On Sun, 30 Apr 2000 05:33:32 -0400, Krogg <krogg DOT no DOT to DOT spam AT gtcom DOT net>
wrote:
> > Therefore you can't "swap" statically allocated arrays without
> > swapping the data float by float.
> I bet you can,I dont know how yet,but i am drinking "Mountian Dew" and
> one day i will stay up long enough to prove it.
I hope "Mountian Dew" isn't an insecticide...
> > You have to define pointers which "correspond" to these arrays - in
> > the same ways as a pointer to char "corresponds" to a an array of
> > char. float[50][50] if an array of array of 50 floats. The
> > corresponding pointer type is the pointer type where the "outer array
> > type" is transformed to pointer, i.e. a pointer to array of 50 float:
> after reading that about 4 times,I an starting to get it.
>
> > float x[100][50];
> > float y[100][50];
>
> Is there some reason you used [100] instead of [50] as
> the first subscript?
Yes. To make explicit the the 50 in the definition of the pointer
float (*p1) [50];
is referring to the second dimension of the original array and not to
the first. The first dimension is always neclected when defining a
pointer which matches an array type.
The same for
float a [10][20][30];
The matching pointer type is
float (*p) [20][30];
/* "pointer to array [20][30] of float"
"replacing array[x] of array [20][30] of float" */
p = a;
The whole story obviously works, too, for dynamically allocated arrays
float (*p1) [50];
float (*p2) [50];
p1 = malloc (100 * sizeof *p1);
p2 = malloc (100 * sizeof *p2);
Now you have two "anonymous" arrays float [100][50] in free store and
p1,p2 are pointing to their respective initial elements (which are
arrays [50] of float).
Regards
Horst
- Raw text -