home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / misc / 4072 < prev    next >
Encoding:
Text File  |  1992-12-22  |  1.4 KB  |  45 lines

  1. Newsgroups: comp.lang.misc
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: Safety. Was: Re: Pointers
  5. Message-ID: <9235707.2967@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. References: <1992Dec16.164821.19079@walter.bellcore.com> <BzD525.Ayv@mentor.cc.purdue.edu>
  9. Date: Mon, 21 Dec 1992 20:41:28 GMT
  10. Lines: 33
  11.  
  12. hrubin@pop.stat.purdue.edu (Herman Rubin) writes:
  13.  
  14. >The expression use_double(...), as
  15. >I intend it, means that the bit pattern, or concatenated bit pattern, 
  16. >described in the parentheses is to be now used as a double number in
  17. >any application.  Therefore, in   process(use_double(...)), process just
  18. >assumes that what is presented to it is a double, just as the cast to
  19. >double declares that the result is double.
  20.  
  21. I don't know why I bother, but here it is anyway...
  22.  
  23. In Gnu C:
  24.     #define use_double(var) ({ \
  25.         union { typeof(var) old; double new; } tmp; \
  26.         tmp.old = var; \
  27.         tmp.new \
  28.     })
  29.  
  30. In C++:
  31.     template<class T>
  32.     double use_double(T var) {
  33.         union { T old; double new; } tmp;
  34.         tmp.old = var;
  35.         return tmp.new
  36.     }
  37.  
  38. Satisfied, Mr. Rubin?
  39.  
  40. -- 
  41. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  42. This .signature virus is a self-referential statement that is true - but 
  43. you will only be able to consistently believe it if you copy it to your own
  44. .signature file!
  45.