home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.std.c++:1170 comp.lang.c++:13584
- Newsgroups: comp.std.c++,comp.lang.c++
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!wupost!sdd.hp.com!usc!sol.ctr.columbia.edu!destroyer!ncar!ico!dirtydog.ima.isc.com!karl
- From: karl@ima.isc.com (Karl Heuer)
- Subject: Re: Exponentiation operator proposal
- Message-ID: <1992Sep13.193507.27813@ima.isc.com>
- Sender: usenet@ima.isc.com (news)
- Organization: Interactive Systems, Cambridge, MA 02138-5302
- References: <23660@alice.att.com>
- Date: Sun, 13 Sep 1992 19:35:07 GMT
- Lines: 33
-
- In article <23660@alice.att.com> bs@alice.att.com (Bjarne Stroustrup) writes:
- >Comments on Mat Austern's proposal for an exponentiation operator
-
- I missed that one, but I've posted about exponentiation a few times myself.
-
- >(1) I think overloading and inlining ...
-
- My only objection to this method (other than the perceived aesthetic
- superiority of an infix operator) is that the later example
- > void f(double d, int i) { ... pow(d,i); ... }
- inline-expands to something that always runtime-compares the variable i with
- certain small integers before invoking the true function _pow(). In some
- sense it would be better to do this only when i is a constant (in which case
- it's a compile-time compare), and have the non-constant-exponent case simply
- call the true function immediately.
-
- This could be accomplished with one addition to the language:
- isconstant(expr) - an operator that returns 1 if expr is a
- constant expression, or 0 if not. If the operand involves
- formal parameters to an inline function, the actual arguments
- are used.
-
- >(2) I think we could actually get ** as the exponentiation operator.
- >[By defining `**' to have semantics of TIMES FETCH when the right operand
- >is a pointer]
-
- I considered this when I wrote my exponentiation essay. I decided that it
- might be possible, but it's way too confusing! This would be a kludge of the
- highest order. It's much better to use syntax that's not already taken --
- I've adopted "*^", as suggested by someone else some years ago. (A hybrid of
- "**" and "^", sort of.)
-
- Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint
-