Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!UCBVAX.BERKELEY.EDU!"Dan Karron From: Dan Karron@UCBVAX.BERKELEY.EDU Newsgroups: comp.sys.sgi Subject: Calling real c-men... Message-ID: <9104082133.AA15472@karron.med.nyu.edu> Date: 8 Apr 91 21:33:21 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: karron@cmcl2.nyu.edu Organization: The Internet Lines: 133 Here is a problem at the border of the C-language. It is on the edge of c's value as a terse, compact language, and a slippery mess when it comes to arrays and pointers. I would like someone to show me that this is really a beautiful feature to be appreciated and loved! Here is my problem. I have allocated a tree of structures, and I want to pass a pointer to a piece of a structure to a subroutine. Now what I want to pass is a Pointer to an 2 dim CONTIGUOUS array of floats (Like a Matrix typedef, in that each float is in storage adjacent to each other, not an array of pointers to a list of floats) In the receiving subroutine, I would like to be able to reference each element in the array pointed to by the same indexes as in the main structure. Here are the decls and deffs: typedef struct LineTag { float l[2][3],V[2][3]; int DrawMe,Inny,Outie; } Line; typedef struct CompositeTag { struct LineTag *HotLinePointer; struct LineTag SkeweringLines[HOT_SPOTS][HOT_LINES]; struct LineTag LineTween[HOT_SPOTS][HOT_LINES]; Matrix CompositeMatrix; int NumberCompositeStacks,HotStack, HotSlice,HotCardinal,HotLine; char CompositeName[80]; } Composite; Now I want to call a subroutine that works on the vertices of the line as an array of two sets of three plane normal coeff. Hence the decl of the Line as a 2 by 3 array. If I want to operate on the substituent planes, they I want to pass a pointer to the individual plane. If I want to work on the line, I want to pass a pointer to a pair of planes. I want to pass a LIST of lines, or a LIST of planes, where there can be an arbitrary number of elements. I can do this by blinding the compiler with void * and &p->LineInstance.V[0][0] but I would like the debugger and the comiler to know the array bounds for what is pointed by. So, How do I get this meta-code to fly? I gets lots of compiler complaints, Here is what it says: ---------------------------------------------------------------------------- void NitherNoid(int mm,float llist[][2][3],float point[3]); void KnitItTight() { register int i,j,l; static int svd_line_count; float *svd_line_list[2][3]; /* a list of pointers to lines */ svd_line_coune=0; svd_line_list=(void *)0; for(i=0;iComposite->SkeweringLines[l][i].DrawMe) continue; svd_line_count++; if(svd_line_list) /* allocate list space as we need it */ { svd_line_list=realloc(svd_line_list,svd_line_count*sizeof(float *)); } else { svd_line_list=calloc(svd_line_count,sizeof(float *)); } svd_line_list[svd_line_count-1]= &ArenaDirectory->Composite->SkeweringLines[l][i].V; /* attach a pointer to our line */ } if(svd_line_count > 1) { NitherNoid(svd_line_count,svd_line_list,ArenaDirectory->Composite->CardinalMark[l].v); ArenaDirectory->Composite->CardinalMark[l].DrawMe=TRUE; printf("%s:%f,%f,%f\n",ArenaDirectory->Composite->CardinalMark[l].MarkName, ArenaDirectory->Composite->CardinalMark[l].v[0], ArenaDirectory->Composite->CardinalMark[l].v[1], ArenaDirectory->Composite->CardinalMark[l].v[2]); } free(svd_line_list); } /******************************************************************************/ The compiler won't let me attach a pointer to the array of line params. karron:~/D.Image/D.Arenas/D.PixelPicker:159make .c.o RULE PixelPicker.o : triggered by PixelPicker.c cc -DDEBUG -DDANS_HACK -DIRIS_NEWS -I/usr/people/karron/D.Include -g 2 -prototypes -float -c PixelPicker.c ccom: Error: PixelPicker.c, line 140: illegal lhs of assignment operator svd_line_list=(void *)0; -----------------------^ ccom: Error: PixelPicker.c, line 149: illegal lhs of assignment operator svd_line_list=realloc(svd_line_list,svd_line_count*sizeof(fl oat *)); ---------------------------------------------------------------------- -------^ ccom: Error: PixelPicker.c, line 153: illegal lhs of assignment operator svd_line_list=calloc(svd_line_count,sizeof(float *)); --------------------------------------------------------------^ ccom: Warning: PixelPicker.c, line 155: & before array or function: ignored svd_line_list[svd_line_count-1]= &ArenaDirectory->Composite->Skeweri ngLines[l][i].V; ---------------------------------------------------------------------- ---------------^ ccom: Error: PixelPicker.c, line 155: illegal lhs of assignment operator svd_line_list[svd_line_count-1]= &ArenaDirectory->Composite->Skeweri ngLines[l][i].V; ---------------------------------------------------------------------- ---------------^ ccom: Error: PixelPicker.c, line 161: bounds of array argument and prototype disagree: 3 vs 2 NitherNoid(svd_line_count,svd_line_list,ArenaDirectory->Composite->C ardinalMark[l].v); ---------------------------------------------------------------------- ----------------^ How do I make a list of pointers to a 2 dim array that works ? Cheers! dan. | karron@nyu.edu (e-mail alias ) Dan Karron, Research Associate | | Phone: 212 263 5210 Fax: 212 263 7190 New York University Medical Center | | 560 First Avenue Digital Pager <1> (212) 397 9330 | | New York, New York 10016 <2> 10896 <3> |