home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!darwin.sura.net!jvnc.net!gmd.de!Germany.EU.net!mcsun!sunic!seunet!swbull!hemulen.bull.se!elias
- From: elias@proxxi.se (Elias M}rtensson (proxxi))
- Subject: Re: Functions Within Functions
- Message-ID: <1992Jul30.004828.3153@proxxi.se>
- Organization: proxxi
- References: <Bs5w39.5ox@news.larc.nasa.gov> <1992Jul29.194054.19035@CSD-NewsHost.Stanford.EDU>
- Date: Thu, 30 Jul 1992 00:48:28 GMT
- Lines: 47
-
- amorgan@Xenon.Stanford.EDU (Crunchy Frog) writes:
-
- >In article <Bs5w39.5ox@news.larc.nasa.gov>
- > wjb@cscsun2.larc.nasa.gov (William J. Bene) writes:
-
- >>Is there any way to declare functions within another function like in pascal?
-
- >Not according to ANSI C. GCC 2.x allows you to do it so you can use
- >that (beware, it is still fairly buggy). BTW - Why do you want to
- >do this? Occasionally I imagine it might be useful for encapsulating
- >code, but if a function is used in only one place I make it static
- >and avoid the problem that way (and have portable code).
-
- Well, there ARE occations one might want to have encapsulated functions.
- If You make a library which uses lots of functions, there might be
- function name collisions, since You can have several encapsulated
- functions with the same name, You won't have these problems.
-
- Example:
-
- main()
- {
- foo();
- bar();
- }
-
- foo()
- {
- int abcd( int a ) { return a + 10; }
-
- /* Do some things which uses the local function "abcd" */
- }
-
- bar()
- {
- int abcd( int a ) { return a + 20; }
-
- /* Do some other things with this new local function "abcd" */
- }
-
-
- >C Frog
-
- ###################
- # Elias Martenson #
- # elias@proxxi.se #
- ###################
-