Zortech "limitation"

Mark H. Colburn mark at Jhereg.Minnetech.MN.ORG
Wed Feb 14 00:11:51 AEST 1990


In article <48910321.20b6d at apollo.HP.COM> nelson_p at 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 <stdio.h>
	#include <stdlib.h>	/* 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 at Minnetech.MN.ORG
Open Systems Architects, Inc.



More information about the Comp.lang.c mailing list