Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!oliveb!intelca!mipos3!omepd!merlyn From: merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) Newsgroups: comp.unix.questions Subject: Re: why p->member ? Message-ID: <3740@omepd> Date: 9 Aug 88 16:33:26 GMT References: <16734@adm.ARPA> <474@sp7040.UUCP> Sender: news@omepd Reply-To: merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) Organization: Stonehenge; netaccess via BiiN, Hillsboro, Oregon, USA Lines: 39 In-reply-to: jsp@sp7040.UUCP (John Peters) In article <474@sp7040.UUCP>, jsp@sp7040 (John Peters) writes: | 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. | | It needs to be referenced as a pointer. To do that use: | | *p.member | | it is the same as | | p->member Whup. Not quite. *p.member is *(p.member). Try (*p).member instead. That's one reason the -> syntax was introduced (from what I remember in reading the white Bible) -- to prevent having to do a lot of parens for a fairly common operation. Another example: can you imagine typing (*((ARR)+(x+y))) every time you wanted ARR[x+y]? But, the real question (as far as it has been discussed in lang.c, I guess) is "if only pointers are used in ->, and structs in ., howcum the compiler can't figure it out?" Because, it is not PL/1. I don't want an automatic conversion. If I type something like indexvalues[j]->fred[3] += 17 I want to be warned if I forgot that indexvalues is really an array of structs, not array of pointer to struct. Automatic adjustment could lead to maintenance headaches later, or even debugging headaches before it works the first time. Just an opinion. But then again, most of what get said here is. :-) -- Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 on contract to BiiN Technical Publications (for now :-), Hillsboro, Oregonor ...!tektronix!ogcvax!omepd!intelob!merlyn Standard disclaimer: I *am* my employer!