home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / edu / 1528 < prev    next >
Encoding:
Text File  |  1992-09-03  |  4.9 KB  |  112 lines

  1. Xref: sparky comp.edu:1528 comp.lang.fortran:3422 comp.lang.misc:2929 comp.arch:9218 sci.math:10977
  2. Newsgroups: comp.edu,comp.lang.fortran,comp.lang.misc,comp.arch,sci.math
  3. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  4. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  5. Subject: Re: Scientists as Programmers (was Re: Small Language Wanted)
  6. Message-ID: <9224818.3482@mulga.cs.mu.OZ.AU>
  7. Sender: news@cs.mu.OZ.AU
  8. Organization: Computer Science, University of Melbourne, Australia
  9. References: <1992Sep3.020355.20338@u.washington.edu> <2!ln9fc@lynx.unm.edu> <1992Sep3.112944.20996@dbsun.uucp> <Bu08uF.HBC@mentor.cc.purdue.edu>
  10. Distribution: na
  11. Date: Fri, 4 Sep 1992 08:06:00 GMT
  12. Lines: 98
  13.  
  14. hrubin@pop.stat.purdue.edu (Herman Rubin) writes:
  15.  
  16. >In article <1992Sep3.112944.20996@dbsun.uucp> meyer@dbsun.uucp (Don Meyer) writes:
  17. >>In article <2!ln9fc@lynx.unm.edu> john@aquarius.unm.edu (John Prentice) writes:
  18. >> [ re: C++ and complex numbers ]
  19. >>>Fortunately, you wouldn't need to because the designers were not brain
  20. >>>dead enough to leave in out in the first place :-) .
  21. >
  22. >>'C' was intended as more of a systems language, in which case complex
  23. >>numbers aren't usually needed.  C++ extends C without any particular
  24. >>bias towards features for specific applications areas.  The philisophy
  25. >>of extending the language via librarys (which can function quite as
  26. >>nicely as built-in features) is a sound one.
  27. >>I would hardly characterize this _considered choice_ as "brain-dead".
  28. >
  29. >This is not brain-dead, but it is certainly brain-damaged.  Inlining of
  30. >stuff from libraries has to be done at compile time, or at most at assemble
  31. >time, as at least the compiler needs to know how much space the inlined
  32. >code will take.  If every addition, etc., required a subroutine call,
  33. >the computer would run very much slower.  So one would have to use 
  34. >some type of language extension file at compile time, not libraries.
  35.  
  36. "Libraries" may include both source code and object code.
  37. (I think the problem here is just that you are using a different definition
  38. of "library".)
  39. The normal way of doing things in C/C++ is put those parts of a library
  40. that will the users will need at compile time in header files (.h).
  41. With C++, the use of inline functions and templates means that more of
  42. the library must be provided as source code than was the case for traditional
  43. C libraries.
  44.  
  45. >The present compilers translate such things as +, *, &, etc., into 
  46. >some version of assembler.  Why not allow the user to say how other
  47. >operations will be similarly translated, and add them to the list?
  48.  
  49. Using any particular assembly language is inherently non-portable, so clearly
  50. this is not a matter which should be addressed by the C standard.
  51. However individual C implementations may provide such a facility as an
  52. extension if desired. Many C/C++ compilers allow inline assembly code;
  53. gcc is one such compiler. For example, the following shows how you can
  54. tell gcc to use the 68881's fsinx instruction:
  55.  
  56.     #include <stdio.h>
  57.     #include <math.h>
  58.  
  59.     #define USE_68881_INSTRUCTIONS 1
  60.  
  61.     #if defined(__GNUC__) && defined(USE_68881_INSTRUCTIONS)
  62.         inline double fast_sin(double arg) {
  63.             double value;
  64.             asm ("fsinx %1,%0": "=f" (value): "f" (arg));
  65.             return value;
  66.         }
  67.     #else
  68.         inline double fast_sin(double arg) { return sin(arg); }
  69.     #endif
  70.     
  71.     int main() {
  72.         printf("%f", fast_sin(3.14159/2));
  73.     }
  74.  
  75. This feature is documented in the gcc-info file (node "Extended asm",
  76. under node "Extensions"). Is that what you wanted?
  77.  
  78. >These operations often produce temporaries; why not tell the user
  79. >how this is done, and let them be added to the list?
  80.  
  81. I'm not quite sure exactly what you are after here. Could you be
  82. a bit more precise about how the user could specify how temporaries
  83. are produced?
  84.  
  85. >These would not really complicate the language design or the compiler,
  86. >except insofar as precedence is affected.
  87.  
  88. Hmmm... Now it sounds like you want operator overloading.
  89. Please don't confuse the notational convenience of operators with 
  90. their usually efficient implementation in terms of single machine
  91. instructions.
  92. C++ allows you to overload existing operators, although to make compiler
  93. writer's jobs easier, it does not allow you to introduce new operators.
  94. This is a separate issue from the ability to write functions that compile
  95. to a single inline machine instruction.
  96.  
  97. >Now why did the C designers use the term "typedef" for what should have
  98. >been called "typealias"?  I have used Fortran compilers before the creation
  99. >of C which allowed a limited number of user-defined types.
  100.  
  101. You could make a strong case that the word "typealias" would be better than
  102. "typedef". If it really bothers you, you can just simply
  103.     #define typealias typedef
  104.  
  105. >Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399
  106.  
  107. -- 
  108. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  109. This .signature virus is a self-referential statement that is true - but 
  110. you will only be able to consistently believe it if you copy it to your own
  111. .signature file!
  112.