Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rtp47.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!mcnc!rti-sel!rtp47!throopw From: throopw@rtp47.UUCP (Wayne Throop) Newsgroups: net.lang.c Subject: C array follies 1 Message-ID: <171@rtp47.UUCP> Date: Wed, 4-Sep-85 16:29:51 EDT Article-I.D.: rtp47.171 Posted: Wed Sep 4 16:29:51 1985 Date-Received: Sat, 7-Sep-85 07:21:48 EDT Organization: Data General, RTP, NC Lines: 33 All right. Put on your C array thinking caps. Consider the following program: void f(x) int x[2][2][2]; { printf( "%o %o %o\n", x, x[0], x[0][0] ); printf( "%d %d %d\n", sizeof(x), sizeof(x[0]), sizeof(x[0][0]) ); } void main(){ int x[2][2][2]; printf( "%o %o %o\n", x, x[0], x[0][0] ); printf( "%d %d %d\n", sizeof(x), sizeof(x[0]), sizeof(x[0][0]) ); f(x); } Clearly the printfs are "illegal", but assume you have a fairly vanilla machine. Eight-bit bytes, four-byte ints. Four-byte pointers. Pointers and ints stored in the same way for argument passing. Two questions: - What does this program print? (Especially what is printed on the last output line?) - Is this "correct"? (Again, especially the last line.) I think that most systems will print "4 16 8" (or equivalent) as the last line. While this is (probably) not a bug, I think it is at least a misfeature. This same point was part of the "C bites" topic, which is what drew my attention to it. The point is *should* C bite in this way, and if so, why? -- Wayne Throop at Data General, RTP, NC !mcnc!rti-sel!rtp47!throopw