Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!veritas!amdcad!mozart.amd.com!proton!tim From: tim@proton.amd.com (Tim Olson) Newsgroups: comp.lang.c Subject: Re: sizeof and multi-dimensional arrays Message-ID: <1991Jan5.210031.28797@mozart.amd.com> Date: 5 Jan 91 21:00:31 GMT References: <1991Jan5.050613.22303@Neon.Stanford.EDU> Sender: usenet@mozart.amd.com (Usenet News) Reply-To: tim@amd.com (Tim Olson) Organization: Advanced Micro Devices, Austin, TX Lines: 25 In article fred@prisma.cv.ruu.nl (Fred Appelman) writes: | In <1991Jan5.050613.22303@Neon.Stanford.EDU> dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) writes: | | >Is the following a compiler bug or am I just confused? | > | >char x[2][3]; | > | > sizeof (*x) gives 6 | > sizeof (x[0]) gives 3. | > | >What's the scoop? | > | | You are just confused. | 'x' is a two dimensional array of 2*3 elments of type char. Makes a total of | 6. 'x[0]' and 'x[1]' are arrays with a length of 3 elements. So both arrays | have a size of 3. That is correct, but the first sizeof is '*x', not 'x'. Thus, it appears to be a compiler bug -- they both should result in '3'. -- -- Tim Olson Advanced Micro Devices (tim@amd.com)