Re: Ahead of "main"?
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 29 Apr 2007 22:54:32 GMT
In article <463503c7$0$16366$88260bb3@xxxxxxxxxxxxxxxxx>,
Stephen Sprunk <stephen@xxxxxxxxxx> wrote:
Going quite methodically through K& R ( as some of you can attest
to!), I have never seen a big diffference in declaring a function
within "main" or "ahead" of it. Now, (p119, K&R II), the discussion
states that "functions "whatever" " should be declared ahead of
main.
Is there a good reason for this?
In Standard C, functions cannot be declared "within" main(); these are
called nested functions and are implemented as an extension by some
compilers, but in general you should never use them. Therefore, the debate
is about whether to declare functions before or after main().
This would be true if you said "defined" rather than "declared". It's
perfectly legal to declare functions in main(), for example:
int main(void)
{
int foo(void);
...
and this does not create nested functions. It's not however
a common style.
-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
.
- References:
- Ahead of "main"?
- From: mdh
- Re: Ahead of "main"?
- From: Stephen Sprunk
- Ahead of "main"?
- Prev by Date: Re: Ahead of "main"?
- Next by Date: Re: break statement in a for loop
- Previous by thread: Re: Ahead of "main"?
- Next by thread: Re: Ahead of "main"?
- Index(es):
Relevant Pages
|