home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / fortran / 3262 < prev    next >
Encoding:
Internet Message Format  |  1992-08-29  |  2.3 KB

  1. Path: sparky!uunet!olivea!mintaka.lcs.mit.edu!ai-lab!life.ai.mit.edu!burley
  2. From: burley@geech.gnu.ai.mit.edu (Craig Burley)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: Small Language Wanted
  5. Message-ID: <BURLEY.92Aug28115438@geech.gnu.ai.mit.edu>
  6. Date: 28 Aug 92 15:54:38 GMT
  7. References: <9224107.5975@mulga.cs.mu.OZ.AU> <17jmqfINNmrc@network.ucsd.edu>
  8. Sender: news@ai.mit.edu
  9. Organization: Free Software Foundation 545 Tech Square Cambridge, MA 02139
  10. Lines: 60
  11. In-reply-to: mbk@lyapunov.ucsd.edu's message of 27 Aug 92 23:00:31 GMT
  12.  
  13. In article <17jmqfINNmrc@network.ucsd.edu> mbk@lyapunov.ucsd.edu (Matt Kennel) writes:
  14.  
  15.    How does C know when compiling foo.c the difference :
  16.  
  17.    cc -c foo.c
  18.    cc -o foo foo.o -lm
  19.  
  20.    vs.
  21.  
  22.    cc -c foo.c
  23.    cc -c pow.c
  24.    cc -o foo foo.o pow.o -lm
  25.  
  26.    ???
  27.  
  28.    Or is this a resolved problem?
  29.  
  30. It's resolved, in essentially the same way as:
  31.  
  32. prog.f:
  33.       PRINT *,MAX(3,4)
  34.       END
  35.  
  36. max.f:
  37.       INTEGER FUNCTION MAX(I,J)
  38.       MAX = I+J
  39.       END
  40.  
  41. g77 -c prog.f
  42. g77 -o prog prog.o ...
  43.  
  44. vs.
  45.  
  46. g77 -c prog.f
  47. g77 -c max.f
  48. g77 -o prog prog.o max.o ...
  49.  
  50. In Fortran, the lack of "EXTERNAL MAX" or equivalent means you've referred
  51. to MAX the intrinsic in prog.f, independent of whether you've got an external
  52. function named MAX.  In C, the use of "#include <math.h>" means you've
  53. referred to the "built-in" pow(), independent of whether you've got an external
  54. function named pow().  Of course, C doesn't have to keep the built-in names
  55. separate from the external names like Fortran, so in Fortran you can always
  56. be sure that prog.f invokes MAX the intrinsic while other program units could
  57. still invoke MAX your external function, while in C, you might or might not
  58. get away with that, depending on the system you're using (i.e. it's not
  59. portable).
  60.  
  61.    Question:  Do you know which real live C compilers that people can buy or
  62.    steal which do in fact perform the optimizations that we're talking about?
  63.  
  64. Well, I know GNU C has code to replace things like memcpy() with machine
  65. code, sometimes depending on things like small amount of data being copied,
  66. so it could use the same mechanism to handle pow() if it wanted.  But I haven't
  67. looked at this for some time.  And I don't know if that code is enabled on any
  68. machines anyway, though it might be.
  69. --
  70.  
  71. James Craig Burley, Software Craftsperson    burley@gnu.ai.mit.edu
  72. Member of the League for Programming Freedom (LPF)
  73.