Path: utzoo!utgpu!water!watmath!clyde!bellcore!rutgers!ucsd!ames!oliveb!olivey!jerry From: jerry@olivey.olivetti.com (Jerry Aguirre) Newsgroups: comp.unix.questions Subject: Re: why p->member ? Message-ID: <27085@oliveb.olivetti.com> Date: 11 Aug 88 02:52:32 GMT References: <16734@adm.ARPA> <23231@labrea.Stanford.EDU> Sender: news@oliveb.olivetti.com Reply-To: jerry@olivey.UUCP (Jerry Aguirre) Organization: Olivetti ATC; Cupertino, Ca Lines: 38 In article <16734@adm.ARPA> stanonik@nprdc.arpa (Ron Stanonik) writes: >While explaining pointers to structures someone asked why >the -> operator was needed; ie, why couldn't the members be >referenced as p.member. Now that everyone has explained what the difference between p. and p-> is and what they each mean (which he alread knew), how about answering the question? As a precedent the compiler already handles this type of conversion for arrays. I can declare: char b1[10]; char *b2; and then later refer to both of them as: b1[2] = b2[2]; Now one of these is the actual array and the other is a pointer. The compiler has to generate the same type of derefferencing that it would for a structure refference. I have had real trouble trying to explain this difference to novice C programmers. In particular the difference between: extern char *b1; and extern char b1[]; seems to confuse anyone used to a higher level language. Many will insist that the manual says they mean the same thing. Getting back to structures though. The final point is that if the compiler can tell the difference then it is one less detail for the programmer to worry about. As long as old code would still work then there should be no problem, right? Jerry Aguirre