Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!mcnc!thorin!unc!steele From: steele@unc.cs.unc.edu (Oliver Steele) Newsgroups: comp.lang.c++ Subject: Re: References considered crippled Message-ID: <8501@thorin.cs.unc.edu> Date: 14 Jun 89 23:38:17 GMT References: <6361@columbia.edu> <9483@alice.UUCP> <6362@columbia.edu> Sender: news@thorin.cs.unc.edu Reply-To: steele@unc.cs.unc.edu (Oliver Steele) Distribution: comp.lang.c++ Organization: University Of North Carolina, Chapel Hill Lines: 28 kearns@read.UUCP () writes: >(1) Why use a->b instead of (*c).b? The reason is that (*c).b is ugly >and hard to type. If we had reassignable references, a ptr that is >usually dereferenced, like c, could be declared as a reference cref, >so we could write cref.b instead. The few times we don't want to >derefence could be handled with the cref& notation. Do you need reassignable references for this? It might be simpler to recognize a.b and a->b as synonymous; in fact, a->b could stand for (**a).b, (***a).b, ..., as well as for (*a).b, making code that dealt with Macintosh Handle's, for instance, much easier to read. There's never any ambiguity at compile time as to whether something has fields itself or is a pointer to something that does, and introducing the synonymity doesn't break existing code. The disadvantage of such a scheme is that you can't tell the cost of an expression from looking at it, unless you scan backward for an declaration. You might not think to declare a temporary variable to rewrite a block of code making lots of references to fields of a, but if the code instead referred to fields of (***a) you might wrap it in {register foo *pa = **a; ...} and refer to fields of (*pa) instead. And until optimizing compilers are more common-place, it will be more important to some people that computationally expensive code look expensive, than that conceptually simple code look simple. --------------------------------------------------------------------------- Oliver Steele ...!decnet!mcnc!unc!steele UNC-CH Linguistics steele@cs.unc.edu