Path: utzoo!utgpu!water!watmath!clyde!rutgers!sunybcs!bingvaxu!leah!itsgw!imagine!pawl21.pawl.rpi.edu!kyriazis From: kyriazis@pawl21.pawl.rpi.edu (George Kyriazis) Newsgroups: comp.lang.c Subject: Re: Array problems. [Was: reply to GEORGE KRYKARISS] Message-ID: <371@imagine.PAWL.RPI.EDU> Date: 16 Feb 88 03:44:00 GMT References: <11829@brl-adm.ARPA> Sender: news@imagine.PAWL.RPI.EDU Reply-To: kyriazis@pawl21.pawl.rpi.edu (George Kyriazis) Organization: RPI Public Access Workstation Lab - Troy, NY Lines: 104 In article <11829@brl-adm.ARPA> kcfy@hp1.ccs.cornell.EDU (Oya Ekin) writes: > >GEORGE KYRIAZISSS writes :: > noooooo.... My name is George Kyriazis.. :-) >> Hello world. I first found that peculiar behaviour trying to >> write a computer graphics program involving points, lines and polygons. >> Anyway, here it is: >> >> int (*lines)[2]; >> main() {} >> >>is a dummy program that just defines this data structure. What I actually >>want is a pointer to arrays of 2 ints. I believe that int *lines[2] will >>do the reverse, ie. give me two pointers to int. >>Anyway, when I run it thru dbx on a SUN and ask 'whatis lines' I get this: >> >> int (*lines)[8196]; >> >>As far as I know, this is a *BIG* mistake? Or am I wrong? >> >> > I do not quite understand how you are going to use a declaration like >the one you gave. BUT You are right ... I compiled this on Vax it >gives me array[0..1] of (*lines) but I do not understand how you are >going to use this even if it is declared correctly as in VAX. > >MAYBE you need something like : > >int *lines ; > >main() >{ > lines = calloc(2*n,sizeof(int)) ; >} > >to create arrays of 2 ints refernced as > for example for a point : > line[n] for x and line[n+1] for y ; > You are right, this thing will work.. Even defining a structure like struct lines {int e1,e2} *lines; will work. What I was thinking of doing was lines=(int (*)[2])malloc(sizeof(int)*2*nelem); so I can reference as lines[i][0] and lines[i][1]. (Don't worry about the (int (*)[2]) casting... It works.. I have no idea why, but it does..) But here there is a problem between debuggers.. I compiled it to a vax, an iris 3130 workstation and an Balance 21000 and here is what I got: On the VAX: csv.rpi.edu 10% dbx dbx version 3.21 of 6/5/86 16:40 (monet.Berkeley.EDU). Type 'help' for help. enter object file name (default is `a.out'): reading symbolic information ... (dbx) whatis lines array[0..1] of int *lines; (dbx) On the iris: iris.cs.rpi.edu 8% dbx enter object file name (default is `a.out'): dbx version 3.99 of 12/19/87 21:33. Type 'help' for help. reading symbolic information ... (dbx) whatis lines array[0..4294967295] of int *lines; (dbx) On the Sequent: b21.cs.rpi.edu 8% dbx temp dbx version 5.7 of 9/10/87 22:48 (Sequent). Type 'help' for help. reading symbolic information ... (dbx) whatis lines array[0..4294967295] of int *lines; (dbx) and finally on the SUN: pawl10.pawl.rpi.edu 4% dbx temp Reading symbolic information... Read 51 symbols (dbx) whatis lines int (*lines)[8196]; (dbx) I have no problem changing my data structure, but do we have a ?major? dbx problem here?? I don't understand.. ******************************************************* *George C. Kyriazis * Gravity is a myth *userfe0e@mts.rpi.edu or userfe0e@rpitsmts.bitnet * \ / *Electrical and Computer Systems Engineering Dept. * \ / *Rensselear Polytechnic Institute, Troy, NY 12180 * || ******************************************************* Earth sucks.