function declaration nested?

P

Phil Reardon

Ive been away from programming for a few years and am having difficulty
accessing a function from a math/engineering library that I want to use .
I thought that double foo(double); inserted in the calling routine would
let me say x=foo(y); But I get a warning from the compilation that says
"warning: nested extern declaration of 'foo'. Thanks for any suggestions
 
M

Micah Cowan

Phil Reardon said:
Ive been away from programming for a few years and am having difficulty
accessing a function from a math/engineering library that I want to use .
I thought that double foo(double); inserted in the calling routine would
let me say x=foo(y); But I get a warning from the compilation that says
"warning: nested extern declaration of 'foo'. Thanks for any suggestions

Please post the minimum compileable (or compile-attemptable) code
that exhibits the problem you are experiencing; until you do that
we can only talk about our suspicions, not point out what we know
to be the problem. "Inserted in the calling routine?"

If you mean you did something like:

void my_name_is_of_no_consequence(void)
{
double foo(double);

x=foo(y);
}

And you got that warning; well, an implementation is within its
rights to complain about anything it wants to. It may be that the
implementation "thinks" that you might have meant to declare
foo() at file-scope, I dunno. As long as it compiles, there isn't
really a problem in this case.

HTH,
Micah
 
O

osmium

Phil said:
Ive been away from programming for a few years and am having difficulty
accessing a function from a math/engineering library that I want to use .
I thought that double foo(double); inserted in the calling routine would
let me say x=foo(y); But I get a warning from the compilation that says
"warning: nested extern declaration of 'foo'. Thanks for any suggestions

C does not allow nesting of functions, a la Pascal. It may be that what you
want is a *pointer to* a function. That comes up commonly in mathematics.
and C has provisions for that.
 
O

osmium

Daniel said:
http://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_5.html

see nested functions

i couldnt figure out whether this feature refers to gcc-extensions or
to C99 extentions ..

can you say for sure it's not in C99?

No, I can't say for sure, I am not a language maven. But the start of the
paragraph you refer to says:


"GNU C provides several language features not found in ISO standard
C."

Which tells me that *this* is a GNU C extension. I also think it is highly
unlikely that they would start nesting at this point in time.
 
J

Jack Klein

[...]
C does not allow nesting of functions, a la Pascal. It may be that what you
want is a *pointer to* a function. That comes up commonly in mathematics.
and C has provisions for that.

http://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_5.html

see nested functions

i couldnt figure out whether this feature refers to gcc-extensions or
to C99 extentions ..

can you say for sure it's not in C99?

thx

Yes, I can say for sure that the C language does not support nested
functions, and that includes the 1999 version of the standard.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
A

August Derleth

22:46a:

So much that if I were using GNU I might be
tempted to abandon this newsgroup in favor of a GNU newsgroup.

Please, do. At least as long as you wish to discuss nonstandard extensions
to C.
 
I

Irrwahn Grausewitz

August Derleth said:
22:46a:



Please, do. At least as long as you wish to discuss nonstandard extensions
to C.

C'mon, he said /if/, and he didn't discuss nonstandard extensions; the
question was, if a certain feature was (topical) ISO-C or (OT) GNU.

Regards
 
D

Dan Pop

In said:
Please post the minimum compileable (or compile-attemptable) code
that exhibits the problem you are experiencing; until you do that
we can only talk about our suspicions, not point out what we know
to be the problem. "Inserted in the calling routine?"

If you mean you did something like:

void my_name_is_of_no_consequence(void)
{
double foo(double);

x=foo(y);
}

And you got that warning; well, an implementation is within its
rights to complain about anything it wants to. It may be that the
implementation "thinks" that you might have meant to declare
foo() at file-scope, I dunno. As long as it compiles, there isn't
really a problem in this case.

I suspect he's including a header that already provides a declaration
for foo().

Dan
 
D

Dan Pop

In said:
C does not allow nesting of functions, a la Pascal.

The diagnostic is about a nested function declaration, not about a nested
function definition. Probably something like:

#include <math.h>

int main()
{
double sin(double);
return 0;
}

would trigger the same diagnostic. If this is the case, indeed, all the
OP has to do is to drop the declaration of foo inside the calling function
because foo is already declared. He may also want to check that the
declaration that is already in scope is the one he expects.

Dan
 
D

Dan Pop

In said:
But then what did he mean by "inserted in the calling routine?"

The very thing you have illustrated above, but there is already a
declaration for foo() in scope, coming from some included header.

Dan
 

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