Re: external variables



On Wed, 11 Feb 2009 18:10:07 -0800, Keith Thompson wrote:

Larry Gates <larry@xxxxxxxxxxxxxxx> writes:
On Tue, 10 Feb 2009 07:54:55 -0500, pete wrote:
Also, you can have a declaration with the extern keyword
inside of a function definition.

Well, if you can't declare a function from within a function, what use is
the keyword extern going to do you there?

You can't *define* a function within a function definition:

void outer(void) {
void inner(void) { } /* ILLEGAL */
}

You can *declare* a function within a function definition:

void func(void) {
extern void external_function(void); /* OK */
}

but it's no necessarily a good idea. Normally function declarations
like this (prototypes) should be in header files, not buried inside
function definitions.

And that extern is necessary there?
--
larry gates

Perl itself is usually pretty good about telling you what you shouldn't
do. :-)
-- Larry Wall in <11091@xxxxxxxxxxxxxxxxxxxxxxx>
.



Relevant Pages

  • Re: external variables
    ... inside of a function definition. ... Well, if you can't declare a function from within a function, what use is ... the keyword extern going to do you there? ... semantics. ...
    (comp.lang.c)
  • Re: Ahead of "main"?
    ... It's always been possible to *declare* functions within a function ... int outer() ... inner(); /* call function inner, ... or within a function definition. ...
    (comp.lang.c)
  • Re: external variables
    ... Well, if you can't declare a function from within a function, what use is ... the keyword extern going to do you there? ... You can't *define* a function within a function definition: ... void outer{ ...
    (comp.lang.c)
  • Re: including files
    ... (I want to use some functions of the included file, which is not the "main" function, can I just declare the functions I want to use only at the header). ... void f; // declaration, no definition ... That way you can be sure that the prototype matches the actual function definition. ...
    (microsoft.public.vc.language)
  • Re: const and standard types
    ... > function definition you declare the value const, ... > void f(const int i) { ...
    (comp.lang.cpp)