Mail Archives: djgpp/2000/04/30/05:44:25
Horst Kraemer wrote:
>
> On Sat, 29 Apr 2000 19:52:27 -0400, Krogg <krogg DOT no DOT to DOT spam AT gtcom DOT net>
> wrote:
>
> >
> > I got 2 arrays of same type/size.
> >
> > float abc[50][50];
> > float cba[50][50];
> >
> > how can i "swap" them?
> >
> > so that abc[x][y] will now point to cba[x][y] and
> > vice versa...
>
> abc and cba don't point. Don't believe in fairy tales sine
> grandmothers tell you. Arrays are _not_ pointers nor "constant"
> pointers. They are arrays. They have meat. They are "data" like ints
> or floats or structs.
I know that,but the information about the array is stored
SOMEWHERE,and therefore it should be able to be changed...
> 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.
> 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?
> float (*p1)[50];
> float (*p2)[50];
>
> p1 = x;
> p2 = y;
>
> Now you may use p1[3][5]|p2[3][5] in place of x[3][5]|y[3][5] in every
> context. In order to "swap" you just swap the pointers:
>
> void *temp;
>
> temp = p1 ; p1 = p2 ; p2 = temp:
Cool,I test it,and this is exactaly the automagic that
i was looking for.You are truly a wizard.
> Regards
> Horst
Thanks a lot,I been searching all day for a solution and
though i have found some cool things to read,i never found
a solution till i read your post.Thanks.
BE cool,
Krogg.
--
|"""""<`.THE PRINCE ,'>"""""""""""""""""""""""""""""""""""|
| `.`/""""""\,',' my sig is too big, |
|SEE HIS ( / \ \' SEE HIS but its really cool. |
| FACE \/<> <>\/ SMILE |
| / W \ Visit my ascii art site: |
| ,'\_|||||_/`. http://www.gtcom.net/~krogg/ascii/ |
| ,',' ||| `.`. krogg DOT no DOT to DOT spam AT gtcom DOT net |
|____<,' TIME TO DIE `.>____Remove no.to.spam to reply____|
- Raw text -