From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: DJGPP Structs Date: Sun, 09 Mar 1997 02:50:50 -0800 Organization: Alcyone Systems Lines: 43 Message-ID: <3322960A.130E6E39@alcyone.com> References: NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Cristovao Braga wrote: > That's how I'd do it: > > #define max_x 25 > #define max_y 25 > > defPt *View; > > main () > { > View = (defPt *) malloc (sizeof (defPt) * max_x * max_y); > > // referencing > > *(View + x + y * max_x) = 25; [*] > some_int = (View + x + y * max_x)->sx; > } > > You'll get warnings saying that you are converting int to pointer > whithout > a cast. Just ignore them. It works. (Unless someone else knows something > else about it that I don't). Yes: "incompatible types in assignment" (directly from gcc). I don't know what the statement marked with [*] is supposed to do here. Dereferencing a pointer to View gives you a View, not an integral type. This is (along the lines of) the right way to do dynamic allocation if you want to treat memory as a linear space. If you want, however, to treat it as truly a two-dimensional array, then you have to do as I've posted just recently on this group: First, allocate an array of max_x defPt pointers, and then for each of those max_x pointers, allocate an array of max_y defPts. -- Erik Max Francis, &tSftDotIotE / email: max AT alcyone DOT com Alcyone Systems / web: http://www.alcyone.com/max/ San Jose, California, United States / icbm: 37 20 07 N 121 53 38 W \ "I am become death, / destroyer of worlds." / J. Robert Oppenheimer (quoting legend)