function declarations

C

conrad

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?
 
E

Eric Sosman

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."
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top