home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1170 < prev    next >
Encoding:
Internet Message Format  |  1992-09-13  |  2.1 KB

  1. Xref: sparky comp.std.c++:1170 comp.lang.c++:13584
  2. Newsgroups: comp.std.c++,comp.lang.c++
  3. 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
  4. From: karl@ima.isc.com (Karl Heuer)
  5. Subject: Re: Exponentiation operator proposal
  6. Message-ID: <1992Sep13.193507.27813@ima.isc.com>
  7. Sender: usenet@ima.isc.com (news)
  8. Organization: Interactive Systems, Cambridge, MA 02138-5302
  9. References: <23660@alice.att.com>
  10. Date: Sun, 13 Sep 1992 19:35:07 GMT
  11. Lines: 33
  12.  
  13. In article <23660@alice.att.com> bs@alice.att.com (Bjarne Stroustrup) writes:
  14. >Comments on Mat Austern's proposal for an exponentiation operator
  15.  
  16. I missed that one, but I've posted about exponentiation a few times myself.
  17.  
  18. >(1) I think overloading and inlining ...
  19.  
  20. My only objection to this method (other than the perceived aesthetic
  21. superiority of an infix operator) is that the later example
  22. >    void f(double d, int i) { ... pow(d,i); ... }
  23. inline-expands to something that always runtime-compares the variable i with
  24. certain small integers before invoking the true function _pow().  In some
  25. sense it would be better to do this only when i is a constant (in which case
  26. it's a compile-time compare), and have the non-constant-exponent case simply
  27. call the true function immediately.
  28.  
  29. This could be accomplished with one addition to the language:
  30.     isconstant(expr) - an operator that returns 1 if expr is a
  31.     constant expression, or 0 if not.  If the operand involves
  32.     formal parameters to an inline function, the actual arguments
  33.     are used.
  34.  
  35. >(2) I think we could actually get ** as the exponentiation operator.
  36. >[By defining `**' to have semantics of TIMES FETCH when the right operand
  37. >is a pointer]
  38.  
  39. I considered this when I wrote my exponentiation essay.  I decided that it
  40. might be possible, but it's way too confusing!  This would be a kludge of the
  41. highest order.  It's much better to use syntax that's not already taken --
  42. I've adopted "*^", as suggested by someone else some years ago.  (A hybrid of
  43. "**" and "^", sort of.)
  44.  
  45. Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint
  46.