home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!chsun!zurich!gegu
- From: gegu@zurich.spectrospin.ch (Gerry Gucher)
- Newsgroups: comp.lang.c
- Subject: Re: Functions Within Functions
- Summary: declare functions inside functions ? better not
- Message-ID: <176@zurich.spectrospin.ch>
- Date: 30 Jul 92 08:57:02 GMT
- References: <Bs5w39.5ox@news.larc.nasa.gov> <rfries.81@fries_Robert@ub.ub.com>
- Organization: Spectrospin AG, Fallanden Switzerland
- Lines: 39
-
- In article <rfries.81@fries_Robert@ub.ub.com>, rfries@fries_Robert@ub.ub.com (Robert Fries) writes:
- >
- > No, you cannot 'define' a function within the body of another function.
- > Yes, you can 'declare' a function within the body of another function.
- >
- > Robert
-
- Once upon a time it was common to declare functions in a "local context"
- such as inside a function. With the coming up of ANSI C prototypes I
- strongly discourage this practice.
-
- In my opinion any data or code object should be declared only once.
- For global functions (not static) this is in a header file, for static
- functions this is at the top of the source file with the other
- declarations.
-
- Declaring extern functions at various places buys you nothing in
- terms of compiler type checking. If the type of one of your functions
- changes, there is no guarantee that all declarations have been
- updated.
-
- Declaring something like
-
- extern strcpy();
-
- will bite you when you port the code to an IBM system running AIX.
- There strcpy() is a macro and your extern declaration will produce
- a syntax error.
-
- Gerry
-
- +------------------------------------------------------------------+
- | Gerry Gucher gegu@spectrospin.ch |
- | Spectrospin AG, Industriestr 26, 8117 Faellanden Switzerland |
- +------------------------------------------------------------------+
- | A program that returns the wrong | There is nothing wrong with |
- | result twice as fast is infinitely | making mistakes, but make |
- | slower. - H. Spencer | new ones. - D.Sim |
- +------------------------------------------------------------------+
-