Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!rex!rouge!gator.cacs.usl.edu From: pcb@gator.cacs.usl.edu (Peter C. Bahrs) Newsgroups: comp.lang.c Subject: Dynamic and Variable Length Structures Message-ID: <5624@rouge.usl.edu> Date: 21 Mar 90 23:05:00 GMT Sender: anon@rouge.usl.edu Distribution: usa Organization: The Center for Advanced Computer Studies, USL Lines: 36 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@gator.cacs.usl.edu | | 2 Rex Street | | University of Southwestern Louisiana ...!uunet!dalsqnt!gator!pcb | | Lafayette, LA 70504 | +-----------------------------------------------------------------------*/