Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!amdahl!nw From: nw@amdahl.uts.amdahl.com (Neal Weidenhofer) Newsgroups: comp.lang.c Subject: Re: Teaching const Message-ID: <27071@amdahl.uts.amdahl.com> Date: 8 Apr 88 07:30:15 GMT References: <7712@apple.Apple.Com> <3034@haddock.ISC.COM> <613@mcrware.UUCP> <7788@alice.UUCP> Organization: Amdahl Corporation, Sunnyvale CA Lines: 50 Summary: Close but no cigar In article <7788@alice.UUCP>, bs@alice.UUCP writes: > Try reading C declarations backwards (from right to left) they often > make sense that way. The way to read them is from the "inside out". Start with the identifier being declared. The closest type/"*"/"[...]"/"(...)" describes it. The next closest describes that and so on. Just remember that, in the absence of parentheses, things on the right ("[...]" and "(...)") are "closer" than things on the left ("*", etc.). The only exception is storage class which ALWAYS applies directly to the identifier being declared. For example: int * const a; decodes as: a is a constant, a is a constant pointer, a is a constant pointer to an int. (i.e., a cannot be modified but *a can.) while: const int * a; means: a is a pointer, a is a pointer to an int, a is a pointer to a constant int (or int constant.) (i.e., *a cannot be modified but a can.) and a toughie: int (*a[])(); means: a is an array (remember right is "closer" than left) a is an array of pointers, a is an array of pointers to functions, a is an array of pointers to functions that return int. Please, please, please, if you're teaching C, teach them to decode declarations this way. They'll bless you for it. > The ones that don't you might consider simplifying > using typedef. This is ALWAYS a good idea if declarations become unmanageable. The opinions expressed above are mine (but I'm willing to share.) Regards, Neal Weidenhofer And each one there ...{hplabs|ihnp4|ames|decwrl}!amdahl!nw Had one thing shared... Amdahl Corporation And wept when it was all done 1250 E. Arques Ave. (M/S 316) For being done too soon. P. O. Box 3470 Sunnyvale, CA 94088-3470 (408)737-5007