Re: Ahead of "main"?



On Apr 29, 1:40 pm, "Malcolm McLean" <regniz...@xxxxxxxxxxxxxx> wrote:
"mdh" <m...@xxxxxxxxxxx> wrote in message

news:1177877117.874830.65670@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> Hi all,
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?
thanks.

Some early versions of C had local functions, declared within the function
that called them. The idea never caught on, and it is now not possible to
declare functions within main.

Nonsense. There is no problem declaring functions inside main or any
other function. The reasons why you may not want to do so are the
scoping rules, since the declaration would only be visible within the
same block as the declaration. On the other hand, that's perhaps
exactly why you would want to do it on the few occasions where it
makes sense to do so.

.



Relevant Pages

  • Re: Longstanding GNAT bug, bad code, or both -- Answer..Bad code.
    ... I submitted a bugzilla report and it has already been ... declaring a variable as aliased makes it ... The reason ... various access subtypes illegal, ...
    (comp.lang.ada)
  • Re: [OT] Question for ASC Judaism scholars...
    ... reality as applied to someone else and belief without any basis is ... He first makes the assumption that religion is subjective, ... thereby declaring the liberal camp to be correct. ... Take the phrase "when someone uses belief as the reason for ...
    (alt.smokers.cigars)
  • Re: working example File::Taill
    ... A> Couldnt this be a disadvantage in big projects, where declaring ... A> criables at the top of the appropriate scope allows ppl to find *all* ... reason not to do this. ... but the strong consensus is that it is poor style. ...
    (comp.lang.perl.misc)
  • Re: move this Forum somewhere else?
    ... The point is there is no reason to init ... The simple act of declaring a variable's type does ...
    (alt.lang.asm)
  • Re: Split the newsgroup.
    ... We already have a successful moderated newsgroup called ... I see no reason to be elitist, ... keep declaring everything off-topic. ... there is plenty that is not declared off topic because there is plenty you can do with standard C. ...
    (comp.lang.c)