delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/30/21:44:18

Message-ID: <390CEA18.77A5D74D@gtcom.net>
From: Krogg <krogg DOT no DOT to DOT spam AT gtcom DOT net>
X-Mailer: Mozilla 4.61 [en] (Win95; U)
X-Accept-Language: en,en-US,en-GB,ja,af
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Array swapping.
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> <390c1cad DOT 1446232 AT news DOT cis DOT dfn DOT de>
Lines: 77
Date: Sun, 30 Apr 2000 22:21:12 -0400
NNTP-Posting-Host: 12.16.179.40
X-Trace: eagle.america.net 957147867 12.16.179.40 (Sun, 30 Apr 2000 22:24:27 EDT)
NNTP-Posting-Date: Sun, 30 Apr 2000 22:24:27 EDT
Organization: 24hoursupport.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Horst Kraemer wrote:
> 
> 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...

ITs a softdrink,lots of sugar and caffeine.

[snip]

> >
> > >         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.

DUH...Now i get it..

> 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).
> 

By the way,after implementing this,my program is much faster,AND
importantly i have learnt a lot more that i was seeking to.

Thanks again....




-- 


|"""""<`.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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019