Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!ll-xn!mit-eddie!bloom-beacon!oberon!sdcrdcf!ism780c!news From: news@ism780c.UUCP (News system) Newsgroups: comp.lang.c Subject: Re: Teaching const Message-ID: <9719@ism780c.UUCP> Date: 15 Apr 88 03:06:48 GMT References: <7712@apple.Apple.Com> <3034@haddock.ISC.COM> <613@mcrware.UUCP> <7788@alice.UUCP> <27071@amdahl.uts.amdahl.com> <9683@ism780c.UUCP> <786@srs.UUCP> Reply-To: marv@ism780.UUCP (Marvin Rubenstein) Organization: Interactive Systems Corp., Santa Monica CA Lines: 47 In article <786@srs.UUCP> srs!craig@cs.rochester.edu (Craig Schmackpfeffer) writes: >In article <9683@ism780c.UUCP> marv@ism780.UUCP (Marvin Rubenstein) writes: >>In article <27071@amdahl.uts.amdahl.com> nw@amdahl.uts.amdahl.com (Neal Weidenhofer) writes: >>> 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.) >> >>Note that: >> int a[1]; >>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.) >> >>But there must (?) be some difference between the two. How do you teach >>this? >> > >Of course there is a difference! The "int * const a" declaration declares >a pointer to an int. The "int a[1]" declaration ALLOCATES space for an >int and "a" itself is not a pointer, but actually the location of the array. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ But "a" itself a pointer or else *a would not be allowed. Nor would: char p = a; I wrote the >> article. I should have used a smiley. I was discussing the *teaching* problem. Have you ever tried to explain to a novice why: char *p; and char p[1]; mean the same when p is a parameter, but do mean the same when p is not a parameter. Or why: extern char p[]; makes sense, but char p[]; is an error. If your students don't have any problems with this then they are much smarter than mine (smiley used this time :-). Marv Rubinstein -- Interactive Systems