olson@modular.UUCP (Jon Olson) (05/31/88)
> Hello. > > I am current using VAX/VMS C version 2.3-024. Several of my programs > dynamically allocate space which is later referenced using array > reference syntax (eg, in a partial sketch: the variable is declared > "double ****temp[3]" and later referenced with > "temp[index][f][b][y][x]", after having been set to point at arrays of > properly declared pointers). I have no trouble when I compile the > programs /NOOPTIMIZE, but get access violations when I compile > /OPTIMIZE. The only time I have noticed the problem is when I > reference the (declared) array in a loop where the loop variable is > used as the index (ie, "index" in the above example). Apparently the > optimizer attempts to optimize the loop index - and screws up. > > Is there a later version of C that I can get, and is this a known > problem - or should I submit an SPR? > > Thank you, > Eric Hildum > dehildum@ucdavis.ucdavis.edu (Internet) > dehildum@ucdavis.bitnet (BITNET) > ucbvax!ucdavis!dehildum (uucp) I discovered this bug back when VAX-C V2.3 came out and haven't put it up. I just tried out V2.4 yesterday and it still has the same bug. So I'm still running V2.2 which works OK. It seems to be a bug when indexing arrays as vectors of pointers, not just when within loops. VAX-C treats vectors of pointers as if they were arrays instead of properly doing the indirection. The only workaround for it is to do something like the following: { register float *px = plot.xdata[ i ]; register float *py = plot.ydata[ i ]; px[ j ] = i * j; py[ j ] = i + j; } /* This program demonstrates a severe bug in the VMS VAX-C V2.3 and V2.4 C-compilers (V2.2 is OK, though). It seems that the C-compiler treats `plot.xdata' and `plot.ydata' as 2-dimensional arrays of floats instead of as vectors of pointers. In this case, VAX-C scribbles floating point numbers all over the `plot' data structure rather than putting them in the malloc'd buffers. Note, this program works with the `/NOOPT' switch but bombs with the `/OPT' switch. I can't believe that this bug hasn't caused tons of grief! I know that we are still using V2.2 because of this bug. */ #define MAXSETS 4 #define MAXPNTS 5 main() { int i, j; float x, y; char *malloc(); struct PLOTPARAM { float *xdata[ MAXSETS ]; float *ydata[ MAXSETS ]; } plot; for( i = 0; i < MAXSETS; i++ ) { plot.xdata[ i ] = (float *)malloc( MAXPNTS * sizeof(float) ); plot.ydata[ i ] = (float *)malloc( MAXPNTS * sizeof(float) ); } for( i = 0; i < MAXSETS; i++ ) for( j = 0; j < MAXPNTS; j++ ) { plot.xdata[ i ][ j ] = i * j; plot.ydata[ i ][ j ] = i + j; } for( i = 0; i < MAXSETS; i++ ) { for( j = 0; j < MAXPNTS; j++ ) { x = plot.xdata[ i ][ j ]; y = plot.ydata[ i ][ j ]; printf( "%5.1f/%5.1f", x, y ); } printf( "\n" ); } } -- Jon Olson, Modular Mining Systems USENET: {ihnp4,allegra,cmcl2,hao!noao}!arizona!modular!olson INTERNET: modular!olson@arizona.edu