Path: utzoo!utgpu!attcan!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!mailrus!uwmcsd1!ig!agate!ucbvax!decwrl!labrea!denali!karish From: karish@denali.stanford.edu (Chuck Karish) Newsgroups: comp.unix.questions Subject: Re: why p->member ? Summary: For convenience only; it's not necessary. Message-ID: <23231@labrea.Stanford.EDU> Date: 4 Aug 88 16:10:24 GMT References: <16734@adm.ARPA> Sender: news@labrea.Stanford.EDU Reply-To: karish@denali.stanford.edu (Chuck Karish) Organization: Mindcraft, Inc. Lines: 29 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. This is explained in p. 122 of K&R, first edition. Briefly, if we define a structure pointer with struct date { int year, month, day } *pd; then pd->year is equivalent to (*pd).year. The parentheses show that we're dereferencing pd, not year. Interpretation of the sort you discuss, in which the compiler figures out automatically that p is a pointer and decides on its own to dereference it, would be pretty confusing, not to mention inconsistent with the way other pointers are handled. Anyway, it's not part of the language. Chuck Karish ARPA: karish@denali.stanford.edu BITNET: karish%denali@forsythe.stanford.edu UUCP: {decvax,hplabs!hpda}!mindcrf!karish USPS: 1825 California St. #5 Mountain View, CA 94041