Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!rpi!sci.ccny.cuny.edu!phri!marob!cowan From: cowan@marob.masa.com (John Cowan) Newsgroups: comp.std.c++ Subject: Re: "->" == "." proposal Message-ID: <27304544.3658@marob.masa.com> Date: 1 Nov 90 15:54:43 GMT References: <52390002@hpcupt1.cup.hp.com> Organization: The Logical Language Group, Inc. Lines: 36 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. 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. Implicit dereferencing does exist elsewhere in the C language: a pointer to function is implicitly dereferenced when an attempt is made to call using it, so that (*pfi)() and pfi() mean the same thing, where pfi is of type "pointer to function returning int". 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 *.) 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. -- cowan@marob.masa.com (aka ...!hombre!marob!cowan) e'osai ko sarji la lojban