Mail Archives: djgpp/1997/03/09/08:45:42
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 -