cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/09/08:45:42

From: Erik Max Francis <max AT alcyone DOT com>
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: <B0000041676 AT datasoft DOT datasoft DOT com DOT br>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
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)

- Raw text -


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