Path: utzoo!mnetor!uunet!tektronix!zeus!teklds!daniels From: daniels@teklds.TEK.COM (Scott Daniels) Newsgroups: comp.lang.c Subject: Re: Teaching const Message-ID: <3003@teklds.TEK.COM> Date: 5 Apr 88 20:33:00 GMT References: <7712@apple.Apple.Com> <3034@haddock.ISC.COM> <613@mcrware.UUCP> <3117@haddock.ISC.COM> <3938@chinet.UUCP> <3241@haddock.ISC.COM> <4381@chinet.UUCP> <10203@steinmetz.steinmetz.ge.com> <3300@haddock.ISC.COM> Reply-To: daniels@teklds.UUCP (Scott Daniels) Organization: Tektronix, Inc., Beaverton, OR. Lines: 26 In article <10203@steinmetz.steinmetz.ge.com> davidsen@kbsvax.steinmetz.UUCP (William E. Davidsen Jr) writes: >Could someone give me a good method to use when teaching students C, >such that they will be able to remember the syntax of > pointer to {type} const > - vs - > const pointer to {type} How about: const int *****p; Had better be a pointer to a constant thing (there is no way to identify the pointer that you are talking about): pointer to ... pointer to {type} const "const int i;" and "int const j;" both MUST be talking about constant ints. We can therefore infer that "const int *p;" and "int const *j;" both are also talking about constant ints (since placing "*ptr" where a variable occurs in a declaration is how you build declarations of pointers). Any other meaning assigned to "int const *p;" either violates the "throw in a *ptr" rule, or yields to the "reductio ad absurdum" above. Finally, it seems there is only one place left to put the const when talking about a constant pointer (except following the variable name, but that is really non-C-like), so all we have left is "int * const ptr;". Hope this helps, -Scott Daniels daniels@teklds.UUCP