Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!mcnc!rti!xyzzy!throopw From: throopw@xyzzy.UUCP (Wayne A. Throop) Newsgroups: comp.lang.c Subject: learning C declaration syntax Message-ID: <223@xyzzy.UUCP> Date: Tue, 25-Aug-87 17:04:01 EDT Article-I.D.: xyzzy.223 Posted: Tue Aug 25 17:04:01 1987 Date-Received: Thu, 27-Aug-87 01:42:47 EDT References: <8877@brl-adm.ARPA> <8088@mimsy.UUCP> <1623@tekchips.TEK.COM> <956@bc-cis.UUCP> Organization: Data General, RTP NC. Lines: 54 > john@bc-cis.UUCP (John L. Wynstra) > Sure it's nice now to see the same thing in the declaration as in the > procedural text, and aids like typedef help reduce the problem, but it > took me a long time to figure out the "inside-out" logic required to > read C declarations, and an especially nasty one, like the (*b)[10] > discussed in the net now, will still throw me a little (I write it down > and puzzle it out). 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? Surely it isn't really hard to figure out that a1 is an array of pointers to int, a2 is a pointer to an array of int, and a3 is an array of pointers to functions returning int? Note that I think C's declaration syntax *is* indeed misguided and counterintuitive, especially since this rule is violated (for good reason, which is the point) for structure, enum, and union declarations. But once one knows the rule, why is it still difficult to parse declarations? The question boils down to: Is traditional expression syntax for indirection, subscription, and function invocation hard (for humans) to parse, and is that the reason C declarations are hard (for humans) to parse? If this is so, what does this say about such expressions in general? Does there need to be a cexpr that does for expressions what cdecl does for declarations? Was COBOL right to spell things out in pseudo-english? SUBSCRIPT a3 BY n AND INDIRECT THAT AND INVOKE THAT GIVING i. or EVALUATE 23 GIVING INDIRECT a2 SUBSCRIPTED BY n. or EVALUATE 23 GIVING SUBSCRIPT a2 BY n AND INDIRECT THAT. After all, this is the expression-like equivalent to what people seem to perfer for declarations. I'm not trying to be sarcastic... just wondering. -- "That saw isn't very sharp." --- Comment by the Marquis of Angelsey to the doctor amputating his leg. -- Wayne Throop !mcnc!rti!xyzzy!throop%e