Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pacbell!att-ih!ihnp4!ihlpf!nevin1 From: nevin1@ihlpf.ATT.COM (00704a-Liber) Newsgroups: comp.lang.c++ Subject: Re: User defined operators Message-ID: <4549@ihlpf.ATT.COM> Date: 27 Apr 88 01:12:51 GMT References: <4444@ihlpf.ATT.COM> <1206@its63b.ed.ac.uk> Reply-To: nevin1@ihlpf.UUCP (00704a-Liber,N.J.) Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 54 BTW, in my original article I was merely explaining why (I thought) that C++ did not allow user-definable operators. I hope that I didn't give the impression that I thought that this is impossible to define within the language. In article <1206@its63b.ed.ac.uk> db@itspna.ed.ac.uk (Dave Berry) writes: > Expression C parse (C++)++ parse > > a+++++b "a" "++" "+" "++" "b" "a" "+++++" "b" > *++p "*" "++" "p" "*++" "p" > >However, C++ isn't source code compatible with C anyway, and this scheme >would make the existing treatment of "/*" and "*/" examples of a general rule >rather than a specific case. There is very little that makes C programs choke in the C++ translator. If you fix the header files up (put in function prototypes, which will be required by ANSI C anyway) and don't use any of the new keywords (I know there are a few more little things but I don't have the C++ book handy right now), I can compile my C program with my C++ compiler. Changing the rules from C to C++ is very undesirable. >It would probably also make cases like the above >easier to read, as they would have to be broken up: I agree, but this should not be a design goal of the language (this does not give me more expressive power, so why put it in?). A few things. First, a syntax would have to be devised to allow the overloading of the user-defined operators for the builtin types, such as char, int, etc. Secondly, what do you do about defining the order of precedence and associativity of these user-defined operators? If you make them all the same, then what do you really gain by having infix instead of prefix; you still need parens all over the place. And where in the chart would you put it? Thirdly, there might be some problem in differentiating (at compile time) which operators return lvalues and which do not. Fourthly (is that a word? :-)), I wouild also like to be able to define my own unary operators (both prefix and postfix). Otherwise the same question which started this discussion comes up :-). I am not saying that it is impossible to allow user-definable operators in C++, only that it may not be desirable and that if it is desirable it needs a lot more planning than we have done so far. -- _ __ NEVIN J. LIBER ..!ihnp4!ihlpf!nevin1 (312) 510-6194 ' ) ) "The secret compartment of my ring I fill / / _ , __o ____ with an Underdog super-energy pill." / (_