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

  1. Xref: sparky comp.lang.fortran:3278 comp.std.c:2537
  2. Path: sparky!uunet!mcsun!Germany.EU.net!math.fu-berlin.de!Sirius.dfn.de!darwin.sura.net!wupost!cs.utexas.edu!swrinde!network.ucsd.edu!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. Newsgroups: comp.lang.fortran,comp.std.c
  5. Subject: Re: Small Language Wanted
  6. Message-ID: <9224317.28165@mulga.cs.mu.OZ.AU>
  7. Date: 30 Aug 92 07:32:38 GMT
  8. References: <DAVIS.92Aug23010605@pacific.mps.ohio-state.edu>     <H.3lvmyc56w&A@lionbbs.bs.open.de>     <1992Aug27.181926.5677@alchemy.chem.utoronto.ca>     <9224107.5975@mulga.cs.mu.OZ.AU>     <DAVIS.92Aug27211418@pacific.mps.ohio-state.edu>     <DAVIS.92Aug28015332@pacific.mps.oh <BURLEY.92Aug29143538@geech.gnu.ai.mit.edu>
  9. Sender: news@cs.mu.OZ.AU
  10. Organization: Computer Science, University of Melbourne, Australia
  11. Lines: 46
  12.  
  13. burley@geech.gnu.ai.mit.edu (Craig Burley) writes:
  14.  
  15. >In article <1992Aug28.181327.25214@newshost.lanl.gov> jlg@cochiti.lanl.gov (Jim Giles) writes:
  16. >
  17. >   I apologise for posting this incorrect statement.  In fact, all library
  18. >   function names in ANSI standard C are reserved - the user can't define
  19. >   his own.  So the above comment only applies to old K&R implementations
  20. >   which allow the user to do so.  (It's what I get for remembering an old
  21. >   public review copy of the C standard better than the final version.)
  22. >
  23. >Hmm, I don't remember this being true.  I thought pow, for example, was
  24. >a reserved word only if one #include'd <math.h>, and so on.  It's hard to
  25. >be sure without trying to grok the standard right now, but the (occasionally
  26. >inaccurate) "ANSI C: A Lexical Guide" seems to suggest that pow is not a
  27. >reserved word in the way if or for is, unless #include <math.h> is present.
  28. >And, okay I pulled out the standard, and it seems to agree with this; pow
  29. >is reserved only if you #include <math.h>.
  30.  
  31. If you don't #include <math.h>, then "pow" is not a "reserved word";
  32. but I think that it *is* reserved as an external identifier.
  33. Thus something like
  34.     static double pow(double x,double y) { ... }
  35. should be fine, but to omit the "static" as in
  36.     double pow(double x,double y) { ... }
  37. could cause problems.
  38. [Maybe someone with copy of the standard in front of them can confirm this.]
  39.  
  40. Note that it makes sense to prevent users from redefining standard library
  41. functions, because doing so could have all sorts of undesireable side-effects.
  42. For example, suppose you redefine pow as
  43.     extern double exp(double), log(double);
  44.     double pow(double x, double y) {
  45.         return exp(y * log(x));
  46.     }
  47. So far, so good. But what if exp happened to be implemented in the
  48. standard library as
  49.     double exp(double x) {
  50.         return pow(2.7182818284, x);
  51.     }
  52. ? Now pow() will call exp() which will call pow() which will call exp()...
  53.  
  54. -- 
  55. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  56. This .signature virus is a self-referential statement that is true - but 
  57. you will only be able to consistently believe it if you copy it to your own
  58. .signature file!
  59.