rgr@m10ux.UUCP (10/01/87)
>I'm not dead sure, but I believe that it would not be legal for >a C compiler to implement big_array using a lookup table. Anyone >with hard facts care to comment? Does the standard say what > > int a[2][2]; > > a[ x * 2 + y ] = 0; > >means? I can see arguments both ways, but it looks like it >might be undefined under a strong-typing interpretation. >-- >Steve Nuchia Of course I'm respectable! I'm old! >{soma,academ}!uhnix1 Politicians, ugly buildings, and whores >!nuchat!steve all get respectable if they last long enough. >(713) 334 6720 - John Huston, Chinatown I'm not sure about the new ANSI std stuff, but in K&R, 2d arrays have to be continuous, because when they are passed to a function, "the argument declaration in the fucntion must include the column dimension; the row dimension is irrelevant, since what is passed is, as before, a pointer." (page 105). So this must work: main() { int i,j; int a[3][3]; foo (a); } int foo(a) int a[][3]; { int i,j; (*(a+1))[2]= 8; } and so a must be contiguous. (by the way, it did work on my VAX) On the previous page, it also says that "Elements are stored by rows..." which also seems to imply continuous to me. -- +-------------------------------------------------------------------+ | Duke Robillard {ihnp4!}m10ux!rgr | | Disclaimer: I claim to live in Dis. | +-------------------------------------------------------------------+