Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!sdcsvax!sdcc6!ix426 From: ix426@sdcc6.ucsd.EDU (tom stockfish) Newsgroups: comp.lang.c Subject: Re: Power operator? Message-ID: <3572@sdcc6.ucsd.EDU> Date: 11 Jan 88 00:44:12 GMT References: <47000029@uxe.cso.uiuc.edu> <5260001@hplsla.HP.COM> Reply-To: ix426@sdcc6.ucsd.edu.UUCP (tom stockfish) Organization: University of California, San Diego Lines: 28 In article <5260001@hplsla.HP.COM> jima@hplsla.HP.COM ( Jim Adcock) writes: >Don't use ANSI-C, use C++, and overload the -> operator. >Then you can write: twoToTheTenth = 2.0->10.0; So when will C++ be available on enough machines that we numerical users can write in it and be assured of support when we change employers/machines? The C code that is emitted by CC is *not* portable, chiefly because things like getchar() are already expanded into their machine-specific inline code. Even if this problem could be gotten around, I would hate to have to maintain that C code. I like your choice for the operator. It seems to me this would work nicely if ANSI-C adopted it. It will *not* work for the example you give (2.0->10.0) because at least one operand of an overloaded operator must be a class object. (See Stroustrup's book p. 172). Supplying a trivial floating point class and supplying identity-operation constructors for it should do the trick, but you still won't be able to do constant -> constant without using a cast. If I'm wrong about this, or C++ has been extended to allow overloading of operators on basic types when the basic types don't have a normal meaning with an operator, I would like to hear about it. -- || Tom Stockfisch, UCSD Chemistry tps@chem.ucsd.edu