From: horst DOT kraemer AT gmx DOT de (Horst Kraemer) Newsgroups: comp.os.msdos.djgpp Subject: Re: Array swapping. Date: Sun, 30 Apr 2000 12:52:36 GMT Lines: 61 Message-ID: <390c1cad.1446232@news.cis.dfn.de> References: <390B75BB DOT 621F846A AT gtcom DOT net> <390bf4ba DOT 51457508 AT news DOT cis DOT dfn DOT de> <390BFDEB DOT 42A8D686 AT gtcom DOT net> NNTP-Posting-Host: brln-3e357799.pool.mediaways.net (62.53.119.153) X-Trace: fu-berlin.de 957099089 9660585 62.53.119.153 (16 [27606]) X-Newsreader: Forte Free Agent 1.11/32.235 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Sun, 30 Apr 2000 05:33:32 -0400, Krogg 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