function declaration nested?

Discussion in 'C Programming' started by Phil Reardon, Oct 11, 2003.

  1. Phil Reardon

    Phil Reardon Guest

    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
     
    Phil Reardon, Oct 11, 2003
    #1
    1. Advertising

  2. Phil Reardon

    Micah Cowan Guest

    "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


    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
     
    Micah Cowan, Oct 11, 2003
    #2
    1. Advertising

  3. Phil Reardon

    osmium Guest

    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.
     
    osmium, Oct 11, 2003
    #3
  4. [...]

    > 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
     
    Daniel Schüle, Oct 11, 2003
    #4
  5. Phil Reardon

    osmium Guest

    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.
     
    osmium, Oct 11, 2003
    #5
  6. Phil Reardon

    Jack Klein Guest

    On Sat, 11 Oct 2003 16:53:38 +0200, "Daniel Schüle"
    <> 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
     
    Jack Klein, Oct 11, 2003
    #6
  7. "osmium" <> wrote in
    news:bm976a$k756k$-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.
     
    August Derleth, Oct 12, 2003
    #7
  8. August Derleth <libertarian232003**@onewest.net> wrote:

    >"osmium" <> wrote in
    >news:bm976a$k756k$-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
    ()
     
    Irrwahn Grausewitz, Oct 12, 2003
    #8
  9. Phil Reardon

    Dan Pop Guest

    In <> Micah Cowan <> 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

    >
    >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, Oct 13, 2003
    #9
  10. Phil Reardon

    Dan Pop Guest

    In <bm8tc7$jq7lf$-berlin.de> "osmium" <> 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, Oct 13, 2003
    #10
  11. Phil Reardon

    Micah Cowan Guest

    (Dan Pop) writes:

    > In <> Micah Cowan <> 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

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


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

    -Micah
     
    Micah Cowan, Oct 13, 2003
    #11
  12. Phil Reardon

    Dan Pop Guest

    In <> Micah Cowan <> writes:

    > (Dan Pop) writes:
    >
    >> In <> Micah Cowan <> 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
    >> >
    >> >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().

    >
    >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
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Oct 14, 2003
    #12
    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. Ovidesvideo
    Replies:
    4
    Views:
    552
    Andrey Tarasevich
    Dec 10, 2004
  2. Replies:
    4
    Views:
    1,132
    Richard Tobin
    Dec 12, 2006
  3. Bolin
    Replies:
    4
    Views:
    420
  4. Luca Forlizzi
    Replies:
    4
    Views:
    486
    Luca Forlizzi
    Nov 14, 2010
  5. Richard A. DeVenezia

    Nested function X vs. nested varX = function

    Richard A. DeVenezia, Sep 8, 2003, in forum: Javascript
    Replies:
    1
    Views:
    146
    Code Ronin
    Sep 9, 2003
Loading...

Share This Page