Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!SLIC.CELLBIO.DUKE.EDU!jit From: jit@SLIC.CELLBIO.DUKE.EDU (Jit Keong Tan) Newsgroups: comp.sys.sgi Subject: Re: Calling real c-men...(supplement) Message-ID: <9104090500.AA12480@slic.cellbio.duke.edu> Date: 9 Apr 91 05:00:55 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: jit@slic.cellbio.duke.edu Organization: The Internet Lines: 62 In message <9104082133.AA15472@karron.med.nyu.edu> >>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. It just occurred to me that I may not reply to some of your message, which is probably what you want to know. I usually deference the whole array to a simple one dimension. Then knowing that C array is a column-major array, I can just calculate the position in the array like a matrix. You may not like the way I do it but this will give you a more comfortable feeling about array and pointer. example, ---------- #include #define COL 3 #define ROW 4 main() { int inttype[COL][ROW]; int *odptr; /* one dim. pointer */ int index, in2; odptr = inttype[0]; for (index = 0; index < COL; index ++) for (in2 = 0; in2 < ROW; in2 ++) inttype[index][in2] = in2 + ROW*index; /* If you reverse the order of ROW and COL, for large arrays, this could create a lot of page faults. for (in2 = 0; in2 < ROW; in2 ++) for (index = 0; index < COL; index ++) inttype[index][in2] = in2 + ROW*index; */ /* it is important to declare odptr correctly so that the compiler will know how many bytes to advance In other words, array inttype[2][3] would be : */ *(odptr + 2*ROW + 3) = 7777; for (index = 0; index < COL; index ++) for (in2 = 0; in2 < ROW; in2 ++) printf("col= %d, row=%d, value=%d\n", index, in2, inttype[index][in2]); for (index = 0; index < ROW*COL; index ++) printf("index = %d, content=%d\n",index, *odptr++); /* watch out. odptr points beyond the last element here. */ }