home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13080 < prev    next >
Encoding:
Text File  |  1992-08-30  |  2.0 KB  |  60 lines

  1. Path: sparky!uunet!portal!cup.portal.com!Aurelius
  2. From: Aurelius@cup.portal.com (Mark Christian Barnes)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: complex classes and temporary destruction.
  5. Message-ID: <64992@cup.portal.com>
  6. Date: Mon, 31 Aug 92 00:09:30 PDT
  7. Organization: The Portal System (TM)
  8. Distribution: world
  9. References: <MCGRANT.92Aug26232410@rascals.stanford.edu>
  10.   <23563@alice.att.com> <64821@cup.portal.com> <23578@alice.att.com>
  11.   <64878@cup.portal.com> <23587@alice.att.com> <64915@cup.portal.com>
  12.   <23592@alice.att.com>
  13. Lines: 45
  14.  
  15. Andrew Koenig replies:
  16.  
  17. |>  If operator+(a,b) does, in fact, construct a temporary of type
  18. |> String, then the compiler could determine its storage class,
  19. |> perhaps based upon the storage class of the context to which
  20. |> it is applied.
  21. |
  22. |Sorry, but I'm not going to tell you what operator+(a,b) does.
  23. |I'm compiling it separately and giving you the object code to link
  24. |in with your source code.
  25. |
  26. |Now, how is the compiler going to determine its storage class when
  27. |it is compiling your program?
  28.  
  29.  Hmm, ok. Well then I'll write code defensively like:
  30.  
  31. extern class String;
  32. extern String a, b;
  33.  
  34. void display ( void )
  35. {
  36.   auto String temp;
  37.   auto char const *p;
  38.   auto char const statement[] = "a+b is ";
  39.   auto char const endOfLine[] = ".\n";
  40.  
  41.   temp = a + b;        // invoke String operator+()
  42.   p = temp;        // invoke String operator char const *()
  43.   cout << statement << p << endOfLine;
  44.  
  45. // every variable gets destructed about now. (except cout, a and b)
  46. }
  47.  
  48.  In every case (well, so far ;-}) an unnamed object can be
  49. declared as a variable with a known storage class. This is
  50. why I feel that such "temporary" objects could be treated as
  51. responsibly by a smart compiler. The kind of compiler C++
  52. has been striving towards.
  53.  
  54.  I, as the programmer, can (and usually must) make such
  55. determinations. I sometimes eliminate all unnamed objects during
  56. alpha testing, in order to judge how well I've used the machine's
  57. resources, within my functions and methods.
  58.  
  59.             Regards, Aurelius@cup.portal.com
  60.