Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!udel!rochester!PT!sei!sei.cmu.edu!firth From: firth@sei.cmu.edu (Robert Firth) Newsgroups: comp.lang.c Subject: Re: learning C declaration syntax Message-ID: <2352@aw.sei.cmu.edu> Date: Thu, 3-Sep-87 11:09:37 EDT Article-I.D.: aw.2352 Posted: Thu Sep 3 11:09:37 1987 Date-Received: Sat, 5-Sep-87 11:30:53 EDT References: <8877@brl-adm.ARPA> <8088@mimsy.UUCP> <1623@tekchips.TEK.COM> <956@bc-cis.UUCP> <223@xyzzy.UUCP> Sender: netnews@sei.cmu.edu Reply-To: firth@bd.sei.cmu.edu.UUCP (PUT YOUR NAME HERE) Organization: Carnegie-Mellon University, SEI, Pgh, Pa Lines: 48 In article <223@xyzzy.UUCP> throopw@xyzzy.UUCP (Wayne A. Throop) writes: [ is the syntax of C declarations confusing ] >This is a widespread reaction to C declaration syntax, and in many ways >I can see the point. I thought it arbitrary and bizarre until I read >the explanatory note in the K&R tutorial which states that declaration >syntax mimics expression syntax. But once one knows this about >declarations, why is it still difficult? After all, are assignments >like > > *a1[n] = 23; >or > (*a2)[n] = 23; >or > i = (*a3[n])(); > >confusing? Wayne, I find the syntax of both declaration and use very hard to read. perhaps if I used only C I'd get used to it, but I don't. There seem to me two main sources of confusion for other than C experts. The first is a use of graphical symbols that is, by almost any standard, highly eccentric. That "*" is a good example. Any naive person knows that "*" is the ASCII symbol for "multiply". To use it for indirection is strange. To use it for both indirection AND to mean "POINTER TO" in a declaration is doubly strange. The second cause of confusion is really trivial, but its ramifications are enormous. There are basically three composable structuring symbols in C: "*" (POINTER TO), "[]" (ARRAY OF), and "()" (FUNCTION RETURNING). One uses prefix syntax, the other two use postfix. That is a disastrous error in human engineering. If all three were postfix, I believe C code would be much easier to read. To see what I mean, try reading some Modula-2 code, where all the destructuring operations are postfix; it's easy to see that x[i]^[j].k simply means "take the i'th element of X, dereference, take the j'th element, select the k component. The combination of prefix and postfix syntax also of course creates problems over strength of binding, and hence the need for all those parentheses. You know, to create a binding order problem for essentially monadic operators seems pretty incompetent to me (but I'm biased, as you perceive).