Dynamic and Variable Length Structures
Peter C. Bahrs
pcb at gator.cacs.usl.edu
Thu Mar 22 09:05:00 AEST 1990
I want to write a dynamiclly dimensioned container type (oo flavors)
that is dynamic in the size and number of dimensions, hopefully without
any bounds on either.
Suppose I want to create a thing that can point to integers. So I want to write
Type? *x;
x = dim(3,4,5);
or
dims[0]=3;dims[1]=4;dims[2]=6;dims[3]=4; dims[4]= -1;
Dim (x, dims);
And now to get an integer I want to say: y = Retrieve(x,dims) where dims
now contains the index (i.e. x[2][3][4] or x[4][8])
I CAN put a bound on the dimension and use something like
int ***x; /* 3 dimensions */
x = (int ***) calloc (N1, sizeof (int **));
then for each x[i] : x[i] = (int **) calloc (N2, sizeof (int *));
and x[i][j] = (int *) calloc (N3, sizeof (int));
so: y = x[a][b][c] is valid;
Yuck (or is it?)
Is there any way to parameterize the (int ***) casts into a #define or an
array so that a simple loop index will invoke the appropriate level of cast?
This may imply that x should be of type void *.
Does anyone have any ideas on a solution?
I will post a summary of replies.
/*----------- Thanks in advance... --------------------------------------+
| Peter C. Bahrs |
| The USL-NASA Project |
| Center For Advanced Computer Studies INET: pcb at gator.cacs.usl.edu |
| 2 Rex Street |
| University of Southwestern Louisiana ...!uunet!dalsqnt!gator!pcb |
| Lafayette, LA 70504 |
+-----------------------------------------------------------------------*/
More information about the Comp.lang.c
mailing list