Article View: comp.std.c++
Article #583Re: "->" == "." proposal
From: Dan Banay
Date: Mon, 12 Nov 1990 15:52
Date: Mon, 12 Nov 1990 15:52
71 lines
3062 bytes
3062 bytes
In article <27304544.3658@marob.masa.com>, cowan@marob.masa.com (John Cowan) writes:
> In article <52390002@hpcupt1.cup.hp.com>,
> jamiller@hpcupt1.cup.hp.com (Jim Miller) writes:
> >
> >I'd like suggest a modification for C++:
> > Make "." and "->" equivalent.
>
> I would strongly support the above proposal with one change. Currently,
> -> can be overloaded in classes but "." cannot. So leave -> alone, and
> make "." an operator that accepts either a class/struct or a pointer to
> one, with automatic dereferencing of the pointer. This has no impact
> on existing code, and does not change the compiler much either -- instead
> of reporting an error, it just installs a dereference coercion.
>
I also support the proposed extension -- I can't see any problems it would
cause.
> It seems to me that C would have supported this feature from day one, but for
> the weak type-checking of the C compiler, where the left argument to -> could be
> anything whatever, even an int (interpreted as a raw machine address), and
> the right argument could be any structure tag, even one belonging to a different
> structure. This misfeature has long been removed from all sane compilers,
> and is explicitly forbidden by the ANSI C standard.
One of the (ab)uses of the -> operator (combined with a well-known
anachronism of C), was to determine the offset of a member within a structure.
Case in point:
struct blah {
int a;
double d;
char c;
float e;
};
main()
{
printf("The offset of c is: %d\n",&0->c);
}
A good number of compilers still accept this -- although most will display some
sort of warning.
>
> Also, though I hate to mention the P-word around here,
> in Mesa (Xerox's extended dialect of Pascal) this overloading of "."
> is also done. (Standard Pascal has no analogue of -> but requires explicit
> dereferencing with ^, Pascal's version of unary *.)
The programming language Oberon (Wirth's successor to Modula-2) also does this
overloading.
>
> Would a knowledgeable person tell me by e-mail how to get this idea before
> the ANSI committee? I know the answer is "send in a recommendation";
> what I want is address, format of request, etc.
ditto.
--
+------------------------------------------------------------------------+
| Dan Banay |
| db@tc.fluke.COM {microsoft,sun,uw-beaver}!fluke!db +1 206 356 6285 |
+------------------------------------------------------------------------+
| John Fluke Mfg. Co., MS 223B, PO Box 9090, Everett, WA 98206-9090 USA |
+------------------------------------------------------------------------+
Technical Details
Message-ID:
<1990Nov12.155247.13839@tc.fluke.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!ogicse!milton!uw-beaver!fluke!dbReferences:
<52390002@hpcupt1.cup.hp.com> <27304544.3658@marob.masa.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ogicse!milton!uw-beaver!fluke!db From: db@tc.fluke.COM (Dan Banay) Newsgroups: comp.std.c++ Subject: Re: "->" == "." proposal Message-ID: <1990Nov12.155247.13839@tc.fluke.COM> Date: 12 Nov 90 15:52:47 GMT References: <52390002@hpcupt1.cup.hp.com> <27304544.3658@marob.masa.com> Organization: John Fluke Mfg. Co., Inc., Everett, WA Lines: 71