Xref: utzoo comp.lang.c++:6448 comp.lang.c:25886 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uwm.edu!srcsip!jhereg!mark From: mark@Jhereg.Minnetech.MN.ORG (Mark H. Colburn) Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: Zortech "limitation" Message-ID: <1990Feb13.131151.19688@Jhereg.Minnetech.MN.ORG> Date: 13 Feb 90 13:11:51 GMT References: <48910321.20b6d@apollo.HP.COM> Distribution: usa Organization: Open Systems Architects, Inc., Mpls, MN Lines: 66 In article <48910321.20b6d@apollo.HP.COM> nelson_p@apollo.HP.COM (Peter Nelson) writes: > But they do not apparently offer any way to access memory > 64K > AS 2-DIMENSIONAL ARRAYS, which is the logical data structure > for cellular automata. All I apparently can do with their > product is malloc a chunk of space and access it via pointers. > If I wanted to do pointer arithmetic all over the place I would > use Assembler! Zortech C/C++ is allegedly a high-level language > but their manual describes this as a "limitation" of their product. > I would call it a bug. Well, it is not really a bug. You can malloc the huge hunk of memory and then treat it as a two dimensional array of whatever form you like (or three, or four dimensional as well). The compiler will do the pointer arithmetic for you. It would have to do so regardless of how you declared the array. The following section of code should do what you want: #include #include /* malloc prototype here */ typedef unsigned char my_array_type; my_array_type **my_array; int i; int j; int main() { if ((my_array = malloc((size_t)(WIDTH * HEIGHT))) == NULL) { printf("Malloc error"); exit(1); } for (i = 0; i < HEIGHT; i++) { for (j = 0; j < WIDTH; j++) { my_array[i][j] = i*j; printf("%6d "); } printf("\n"); } } The initialization section is contrived, and is there simply to show that you can use the my_array pointer as if it were declared as: my_array_type my_array[WIDTH][HEIGHT]; With no problems. The code example assumes ANSI C, otherwise the malloc call should be cast correctly, but since Zortech is ANSI Compliant, you shouldn't have any problems. The my_array_type is defined just to show that you could use virtually any type for the array that you want, including structures, etc. -- Mark H. Colburn mark@Minnetech.MN.ORG Open Systems Architects, Inc.