Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!princeton!caip!lll-crg!mordor!ut-sally!cyb-eng!topher From: topher@cyb-eng.UUCP (Topher Eliot) Newsgroups: net.lang.c,net.micro.pc Subject: Re: double (*parray[15])[]; Message-ID: <863@cyb-eng.UUCP> Date: Thu, 22-May-86 12:18:28 EDT Article-I.D.: cyb-eng.863 Posted: Thu May 22 12:18:28 1986 Date-Received: Sat, 24-May-86 21:20:35 EDT References: <200@pyuxv.UUCP> <1181@ncoast.UUCP> <350@dg_rtp.UUCP> <3423@ukma.UUCP> Organization: Cyb Systems, Austin, TX Lines: 82 Xref: watmath net.lang.c:9093 net.micro.pc:8341 (I have dropped net.unix from the newsgroups list). There has been some debate on what the declaration double (*parray[15])[]; means. David Herron seems to be arguing that it declares a zero-length array of some sort, which some people and/or compilers might interpret as being a pointer of the same sort. I admit I found his note a little hard to follow, so maybe I misunderstood him. But I thought I would add my bit of net volume in the form of an explanation of HOW I would go about parsing such a statement. My basic rule, which I have trusted for many years, is to parse it as if it were an expression, starting inside the parentheses, and obeying operator precedence rules: double (*parray[15])[]; ^^^^ 1. It's an array with 15 elements double (*parray[15])[]; ^^^^^^^^^^^ 2. It's an array of 15 pointers. double (*parray[15])[]; ^^^^^^^^^^^^^^^ 3. It's an array of 15 pointers to arrays (the sizes of these arrays being pointed at is not specified). double (*parray[15])[]; ^^^^^^^^^^^^^^^^^^^^^^ 4. It's an array of 15 pointers to arrays of doubles. There's another way to parse it, sort of from the outside in: double (*parray[15])[]; ^^^^^^^^^^^^^^^ 1. The expression (*parray[15])[] has type double. double (*parray[15])[]; ^^^^^^^^^^^^^ 2. The expression (*parray[15]) has type "array of double", with the size of the array unspecified. double (*parray[15])[]; ^^^^^^^^^^ 3. The expression parray[15] has type "pointer to array of double". double (*parray[15])[]; ^^^^^^ 4. parray has type "array of pointers to arrays of doubles", parray has 15 elements. Notice that both these methods are nice and methodical, and they both come up with the same result. I get the impression that at least one of the participants of this discussion parsed the declaration something along the lines of: double (*parray[15])[]; ^^ 1. It's a zero-length array of somethings. double (*parray[15])[]; ^ ^^ 2. It's a zero-length array of pointers to something. double (*parray[15])[]; ^^^^^^^^^^^^^^ 3. It's a zero-length array of pointers to 15-element arrays of something. double (*parray[15])[]; ^^^^^^^^^^^^^^^^^^^^^^ 4. It's a zero-length array of pointers to 15-element arrays of doubles. It is my contention that parsing a declaration this way is just plain wrong, but I admit it's an easy mistake to make, one that I myself made back before I had given this subject as much thought as I have. The original discussion involved lint and malloc; I have nothing to add to that aspect of it, so I am not repeating it here. Cheers, Topher Eliot Cyb Systems, Austin, TX (512) 835-2266 {gatech,harvard,ihnp4,nbires,seismo,ucb-vax}!ut-sally!cyb-eng!topher