🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.ms.programmer
Article #1189

Re: GlobalAlloc and > 2D arrays

#1189
From: Joel Spolsky
Date: Fri, 01 Feb 1991 17:22
19 lines
1492 bytes
In article <27A5D77B.447@ics.uci.edu> ddoherty@ics.uci.edu (Donald Doherty) writes:
>	How does one set up a multidimensional array using GlobalAlloc?
>Especially arrays 3D (i.e. array[i][j][k]) or larger.

C has only limited support for multidimensional arrays, because it is
very hard for the poor compiler to figure out what their dimensions
are, especially if they have been malloc'ed. The best solution is just
to use one-dimensional arrays and figure out the offsets yourself,
i.e. in a 3 x 3 x 3 array, element a[i][j][k] is a[i*9 + j*3 +k]. You
might want to make a macro for that to clarify your code a bit, e.g., 
#define a_(x,y,z) a[(x)*9 + (j)*3 + (k)]
This is what the compiler would do anyway if it could only figure out
what shape your array was.

Hope this helped,

--
Joel Spolsky          // And these streets, Quiet as a sleeping army
spolsky@cs.yale.edu   // Send their battered dreams to heaven.   _Paul Simon
Technical Details
Message-ID: <28472@cs.yale.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cs.yale.edu!spolsky-joel
References: <27A5D77B.447@ics.uci.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cs.yale.edu!spolsky-joel
From: spolsky-joel@cs.yale.edu (Joel Spolsky)
Newsgroups: comp.windows.ms.programmer
Subject: Re: GlobalAlloc and > 2D arrays
Keywords: GlobalAlloc
Message-ID: <28472@cs.yale.edu>
Date: 1 Feb 91 17:22:58 GMT
References: <27A5D77B.447@ics.uci.edu>
Sender: news@cs.yale.edu
Organization: Yale University Computer Science Dept., New Haven, CT 06520-2158
Lines: 19
Nntp-Posting-Host: zoo-gw.cs.yale.edu
Originator: spolsky@suned.CS.Yale.Edu