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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!darwin.sura.net!jvnc.net!gmd.de!Germany.EU.net!mcsun!sunic!seunet!swbull!hemulen.bull.se!elias
  3. From: elias@proxxi.se (Elias M}rtensson (proxxi))
  4. Subject: Re: Functions Within Functions
  5. Message-ID: <1992Jul30.004828.3153@proxxi.se>
  6. Organization: proxxi
  7. References: <Bs5w39.5ox@news.larc.nasa.gov> <1992Jul29.194054.19035@CSD-NewsHost.Stanford.EDU>
  8. Date: Thu, 30 Jul 1992 00:48:28 GMT
  9. Lines: 47
  10.  
  11. amorgan@Xenon.Stanford.EDU (Crunchy Frog) writes:
  12.  
  13. >In article <Bs5w39.5ox@news.larc.nasa.gov> 
  14. >  wjb@cscsun2.larc.nasa.gov (William J. Bene) writes:
  15.  
  16. >>Is there any way to declare functions within another function like in pascal?
  17.  
  18. >Not according to ANSI C.  GCC 2.x allows you to do it so you can use
  19. >that (beware, it is still fairly buggy).  BTW - Why do you want to
  20. >do this?  Occasionally I imagine it might be useful for encapsulating
  21. >code, but if a function is used in only one place I make it static
  22. >and avoid the problem that way (and have portable code). 
  23.  
  24. Well, there ARE occations one might want to have encapsulated functions.
  25. If You make a library which uses lots of functions, there might be
  26. function name collisions, since You can have several encapsulated
  27. functions with the same name, You won't have these problems.
  28.  
  29. Example:
  30.  
  31. main()
  32. {
  33.     foo();
  34.     bar();
  35. }
  36.  
  37. foo()
  38. {
  39.     int abcd( int a )    { return a + 10; }
  40.  
  41.     /* Do some things which uses the local function "abcd" */
  42. }
  43.  
  44. bar()
  45. {
  46.     int abcd( int a )    { return a + 20; }
  47.  
  48.     /* Do some other things with this new local function "abcd" */
  49. }
  50.  
  51.  
  52. >C Frog
  53.  
  54. ###################
  55. # Elias Martenson #
  56. # elias@proxxi.se #
  57. ###################
  58.