why p->member ?
Ron Stanonik
stanonik at nprdc.arpa
Fri Aug 5 00:35:01 AEST 1988
While explaining pointers to structures someone asked why
the -> operator was needed; ie, why couldn't the members be
referenced as p.member. My first response was, we're talking
about pointers to structures, not structures, so a separate
operator is needed. On second thought though, since the
compiler knows whether the variable is a pointer or structure,
why shouldn't the compiler do the "right" thing when it sees
p.member?
Could this ever be ambiguous? That is, is there some declaration
of p such that p could be interpreted as both a structure and
a pointer to a separate structure. I tried fiddling around
with unions, but could not produce such an object.
Does it make a lot more work for the compiler? It doesn't
seem so, since it's already keeping track of p's type.
Thanks,
Ron Stanonik
stanonik at nprdc.arpa
More information about the Comp.unix.questions
mailing list