Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   function declaration nested? (http://www.velocityreviews.com/forums/t315721-function-declaration-nested.html)

Phil Reardon 10-11-2003 04:44 AM

function declaration nested?
 
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


Micah Cowan 10-11-2003 06:11 AM

Re: function declaration nested?
 
"Phil Reardon" <pcr1@pcrt.com> writes:

> 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

osmium 10-11-2003 02:35 PM

Re: function declaration nested?
 
Phil Reardon writes:

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



Daniel Schüle 10-11-2003 02:53 PM

Re: function declaration nested?
 
[...]

> 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

--
Daniel





osmium 10-11-2003 05:22 PM

Re: function declaration nested?
 
Daniel Schüle writes:

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


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.
---
Just scanning the list of GNU extensions supports the pedantic set's
insistence on limiting the newsgroup to standard C. There's an *awful lot*
of stuff there! So much that if I were using GNU I might be tempted to
abandon this newsgroup in favor of a GNU newsgroup.



Jack Klein 10-11-2003 08:24 PM

Re: function declaration nested?
 
On Sat, 11 Oct 2003 16:53:38 +0200, "Daniel Schüle"
<for_usenet2000@yahoo.de> wrote in comp.lang.c:

> [...]
>
> > 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

August Derleth 10-12-2003 11:48 AM

Re: function declaration nested?
 
"osmium" <r124c4u102@comcast.net> wrote in
news:bm976a$k756k$1@ID-179017.news.uni-berlin.de on Sat 11 Oct 2003
11: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.


Irrwahn Grausewitz 10-12-2003 12:36 PM

Re: function declaration nested?
 
August Derleth <libertarian232003**@onewest.net> wrote:

>"osmium" <r124c4u102@comcast.net> wrote in
>news:bm976a$k756k$1@ID-179017.news.uni-berlin.de on Sat 11 Oct 2003
>11: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.


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
--
Irrwahn
(irrwahn33@freenet.de)

Dan Pop 10-13-2003 04:08 PM

Re: function declaration nested?
 
In <m3vfqw9uci.fsf@localhost.localdomain> Micah Cowan <micah@cowan.name> writes:

>"Phil Reardon" <pcr1@pcrt.com> writes:
>
>> 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.


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

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de

Dan Pop 10-13-2003 04:13 PM

Re: function declaration nested?
 
In <bm8tc7$jq7lf$1@ID-179017.news.uni-berlin.de> "osmium" <r124c4u102@comcast.net> writes:

>Phil Reardon writes:
>
>> 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.


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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de


All times are GMT. The time now is 10:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.