function declaration nested?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Reardon

    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

    #2
    Re: function declaration nested?

    "Phil Reardon" <pcr1@pcrt.co m> writes:
    [color=blue]
    > 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[/color]

    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_n o_consequence(v oid)
    {
    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

    Comment

    • osmium

      #3
      Re: function declaration nested?

      Phil Reardon writes:
      [color=blue]
      > 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[/color]

      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.


      Comment

      • Daniel Schüle

        #4
        Re: function declaration nested?

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



        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




        Comment

        • osmium

          #5
          Re: function declaration nested?

          Daniel Schüle writes:
          [color=blue][color=green]
          > > C does not allow nesting of functions, a la Pascal. It may be that what[/color]
          > you[color=green]
          > > want is a *pointer to* a function. That comes up commonly in[/color][/color]
          mathematics.[color=blue][color=green]
          > > and C has provisions for that.[/color]
          >
          > 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?[/color]

          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.


          Comment

          • August Derleth

            #6
            Re: function declaration nested?

            "osmium" <r124c4u102@com cast.net> wrote in
            news:bm976a$k75 6k$1@ID-179017.news.uni-berlin.de on Sat 11 Oct 2003
            11:22:46a:

            [color=blue]
            > So much that if I were using GNU I might be
            > tempted to abandon this newsgroup in favor of a GNU newsgroup.[/color]

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

            Comment

            • Irrwahn Grausewitz

              #7
              Re: function declaration nested?

              August Derleth <libertarian232 003**@onewest.n et> wrote:
              [color=blue]
              >"osmium" <r124c4u102@com cast.net> wrote in
              >news:bm976a$k7 56k$1@ID-179017.news.uni-berlin.de on Sat 11 Oct 2003
              >11:22:46a:
              >
              >[color=green]
              >> So much that if I were using GNU I might be
              >> tempted to abandon this newsgroup in favor of a GNU newsgroup.[/color]
              >
              >Please, do. At least as long as you wish to discuss nonstandard extensions
              >to C.[/color]

              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@free net.de)

              Comment

              • Dan Pop

                #8
                Re: function declaration nested?

                In <m3vfqw9uci.fsf @localhost.loca ldomain> Micah Cowan <micah@cowan.na me> writes:
                [color=blue]
                >"Phil Reardon" <pcr1@pcrt.co m> writes:
                >[color=green]
                >> 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[/color]
                >
                >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_n o_consequence(v oid)
                > {
                > 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
                >implementati on "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.[/color]

                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

                Comment

                • Dan Pop

                  #9
                  Re: function declaration nested?

                  In <bm8tc7$jq7lf$1 @ID-179017.news.uni-berlin.de> "osmium" <r124c4u102@com cast.net> writes:
                  [color=blue]
                  >Phil Reardon writes:
                  >[color=green]
                  >> 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[/color]
                  >
                  >C does not allow nesting of functions, a la Pascal.[/color]

                  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

                  Comment

                  • Micah Cowan

                    #10
                    Re: function declaration nested?

                    Dan.Pop@cern.ch (Dan Pop) writes:
                    [color=blue]
                    > In <m3vfqw9uci.fsf @localhost.loca ldomain> Micah Cowan <micah@cowan.na me> writes:
                    >[color=green]
                    > >"Phil Reardon" <pcr1@pcrt.co m> writes:
                    > >[color=darkred]
                    > >> 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[/color]
                    > >
                    > >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_n o_consequence(v oid)
                    > > {
                    > > 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
                    > >implementati on "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.[/color]
                    >
                    > I suspect he's including a header that already provides a declaration
                    > for foo().[/color]

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

                    -Micah

                    Comment

                    • Dan Pop

                      #11
                      Re: function declaration nested?

                      In <m3zng555px.fsf @localhost.loca ldomain> Micah Cowan <micah@cowan.na me> writes:
                      [color=blue]
                      >Dan.Pop@cern.c h (Dan Pop) writes:
                      >[color=green]
                      >> In <m3vfqw9uci.fsf @localhost.loca ldomain> Micah Cowan <micah@cowan.na me> writes:
                      >>[color=darkred]
                      >> >"Phil Reardon" <pcr1@pcrt.co m> 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_n o_consequence(v oid)
                      >> > {
                      >> > 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
                      >> >implementati on "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.[/color]
                      >>
                      >> I suspect he's including a header that already provides a declaration
                      >> for foo().[/color]
                      >
                      >But then what did he mean by "inserted in the calling routine?"[/color]

                      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@ifh.de

                      Comment

                      Working...