Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!samsung!olivea!uunet!stanford.edu!msi.umn.edu!cs.umn.edu!meuer From: meuer@cs.umn.edu (Mark V. Meuer) Newsgroups: comp.sys.sgi Subject: Re: C compiler bug (optimizer), Irix 3.3.1 Message-ID: <1991May3.151108.23758@cs.umn.edu> Date: 3 May 91 15:11:08 GMT References: <9105021249.16330@godzilla.cgl.rmit.oz.au> Organization: University of Minnesota, Minneapolis, CSci dept. Lines: 65 In <9105021249.16330@godzilla.cgl.rmit.oz.au> mg@GODZILLA.CGL.RMIT.OZ.AU (Mike Gigante) writes: >In the following code: >void > drawbbox(struct bbox bb) >{ > float v[7][3]; > int i; > /* > * a close enough approximation... > */ ... [stuff deleted to save bandwidth] ... > v[7][0] = bb.x1; > v[7][1] = bb.y1; > v[7][2] = bb.z2; (**) > bgnclosedline(); > for(i=0; i < 8; i++) > v3f(v[i]); > endclosedline(); >} >I get an incorrectly draw bbox. From the looks of it, you should get a segmentation fault. You are declaring v to have 7 elements, yet you are filling it with eight (0-7). > Ok, so I did the following: > bgnclosedline(); > for(i=0; i < 8; i++) { > v3f(v[i]); > printf("bbox: %f %f %f\n", v[i][0], v[i][1], v[i][2]); > } > endclosedline(); >and lo and behold, it tells me that the Z value for the last point is >wrong while for the second last point, it is correct. A quick look at >the assignment code shows that in both positions, (see * & **), reveals >that this should *not* happen. Ah, but since the last point is beyond the declared end of the array, it is not defined what will happen. Except, of course, that whatever will happen will be bad. >Mike Gigante, >ACGC >Royal Melbourne Institute of Technology -mark -- Mark Meuer <>< | The Geometry Center | meuer@geom.umn.edu "My guess is that object-oriented programming will be in the 1980's what structured programming was in the 1970's. Everyone will be in favor of it. Every manager will pay lip service to it. Every programmer will practice it