home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11748 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.0 KB  |  51 lines

  1. Path: sparky!uunet!mcsun!chsun!zurich!gegu
  2. From: gegu@zurich.spectrospin.ch (Gerry Gucher)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Functions Within Functions
  5. Summary: declare functions inside functions ? better not
  6. Message-ID: <176@zurich.spectrospin.ch>
  7. Date: 30 Jul 92 08:57:02 GMT
  8. References: <Bs5w39.5ox@news.larc.nasa.gov> <rfries.81@fries_Robert@ub.ub.com>
  9. Organization: Spectrospin AG, Fallanden Switzerland
  10. Lines: 39
  11.  
  12. In article <rfries.81@fries_Robert@ub.ub.com>, rfries@fries_Robert@ub.ub.com (Robert Fries) writes:
  13. >
  14. > No, you cannot 'define' a function within the body of another function.
  15. > Yes, you can 'declare' a function within the body of another function.
  16. > Robert
  17.  
  18. Once upon a time it was common to declare functions in a "local context"
  19. such as inside a function. With the coming up of ANSI C prototypes I
  20. strongly discourage this practice.
  21.  
  22. In my opinion any data or code object should be declared only once.
  23. For global functions (not static) this is in a header file, for static
  24. functions this is at the top of the source file with the other
  25. declarations.
  26.  
  27. Declaring extern functions at various places buys you nothing in
  28. terms of compiler type checking. If the type of one of your functions
  29. changes, there is no guarantee that all declarations have been 
  30. updated.  
  31.  
  32. Declaring something like
  33.  
  34.    extern strcpy();  
  35.  
  36. will bite you when you port the code to an IBM system running AIX.
  37. There strcpy() is a macro and your extern declaration will produce
  38. a syntax error.
  39.  
  40. Gerry 
  41.  
  42. +------------------------------------------------------------------+
  43. | Gerry Gucher                             gegu@spectrospin.ch       |
  44. | Spectrospin AG,  Industriestr 26,  8117  Faellanden Switzerland  | 
  45. +------------------------------------------------------------------+
  46. | A program that  returns the  wrong | There is nothing wrong with |
  47. | result twice as fast is infinitely | making  mistakes,  but make |
  48. | slower.               - H. Spencer | new ones.           - D.Sim |    
  49. +------------------------------------------------------------------+
  50.