function declarations

Discussion in 'C Programming' started by conrad@lawyer.com, Oct 15, 2006.

  1. Guest

    Where in the standard does it say that the following
    definition of foo():

    void foo(void)
    {
    baz();
    }

    int main(void)
    {
    foo();
    return 0;
    }


    acts as both a declaration and a definition but only
    when it precedes the main function?

    --
    conrad
     
    , Oct 15, 2006
    #1
    1. Advertising

  2. Eric Sosman Guest

    wrote:

    > Where in the standard does it say that the following
    > definition of foo():
    >
    > void foo(void)
    > {
    > baz();
    > }
    >
    > int main(void)
    > {
    > foo();
    > return 0;
    > }
    >
    >
    > acts as both a declaration and a definition but only
    > when it precedes the main function?


    Nowhere. There's nothing special about main() in this
    regard.

    A definition is always a declaration (but some declarations
    are not definitions). Most identifiers must be declared before
    they are used; it doesn't much matter whether they are declared
    by a definition or by a non-defining declaration.

    See section 6.2.1 (especially paragraphs 2 and 4) for the
    requirements that boil down to "declare before using."

    --
    Eric Sosman
    lid
     
    Eric Sosman, Oct 15, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Theese

    Local function declarations

    Dave Theese, Sep 5, 2003, in forum: C++
    Replies:
    1
    Views:
    457
    Jack Klein
    Sep 5, 2003
  2. TechCrazy

    const in function declarations

    TechCrazy, Apr 21, 2005, in forum: C++
    Replies:
    6
    Views:
    393
    Grant Schoep
    Apr 24, 2005
  3. Marcus Lessard

    Mangled function type declarations?

    Marcus Lessard, Oct 17, 2003, in forum: C Programming
    Replies:
    1
    Views:
    351
    Eric Sosman
    Oct 17, 2003
  4. Billy Patton

    Function declarations/defaults

    Billy Patton, Nov 14, 2003, in forum: C Programming
    Replies:
    17
    Views:
    546
    Chris Torek
    Nov 19, 2003
  5. Douglas
    Replies:
    2
    Views:
    338
    Herbert Rosenau
    Jul 5, 2004
Loading...

Share This Page