delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/02/00:39:49

Message-ID: <B0000041676@datasoft.datasoft.com.br>
From: "Cristovao Braga" <cbraga AT datasoft DOT com DOT br>
To: "Iain Buchanan" <Iain AT BuchananFamily DOT demon DOT co DOT uk>
Cc: "djgpp list" <djgpp AT delorie DOT com>
Subject: Re: DJGPP Structs
Date: Sun, 2 Mar 1997 02:29:30 -0300
MIME-Version: 1.0

> From: Iain Buchanan <Iain AT BuchananFamily DOT demon DOT co DOT uk>
> 
> struct defPt
> {
>     float x, y, z;
>     int sx, sy;
> };
> 
> And an array full of pointers to such structres:
> defPt *View[25][25];
> 

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

Cristovao Braga.

- Raw text -


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