olson@modular.UUCP (Jon Olson) (05/28/88)
/*
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