Answer to question 4.8 from the FAQ

Discussion in 'C Programming' started by Jean-François Lemaire, Jan 4, 2008.

  1. Hello,

    In the answer to question 4.8 I see this code (copied and pasted):

    -------------------------
    void f(ipp)
    int **ipp;
    {
    static int dummy = 5;
    *ipp = &dummy;
    }
    ....

    int *ip;
    f(&ip);
    -------------------------

    I'm confused about the two first lines. Should'nt the first one be
    written 'void f(**ipp)' and the second one scrapped altogether?

    If not, I don't understand how the above can be legal.

    JFL
    --
    Jean-François Lemaire
     
    Jean-François Lemaire, Jan 4, 2008
    #1
    1. Advertising

  2. Jean-François Lemaire

    Eric Sosman Guest

    Jean-François Lemaire wrote:
    > Hello,
    >
    > In the answer to question 4.8 I see this code (copied and pasted):
    >
    > -------------------------
    > void f(ipp)
    > int **ipp;
    > {
    > static int dummy = 5;
    > *ipp = &dummy;
    > }
    > ...
    >
    > int *ip;
    > f(&ip);
    > -------------------------
    >
    > I'm confused about the two first lines. Should'nt the first one be
    > written 'void f(**ipp)' and the second one scrapped altogether?


    ITYM `void f(int **ipp)'.

    > If not, I don't understand how the above can be legal.


    Question 11.3 has a useful hint, and 11.4 is worth
    a look, too.

    --
     
    Eric Sosman, Jan 4, 2008
    #2
    1. Advertising

  3. On Friday 4 January 2008 17:28, Eric Sosman wrote:
    > Jean-François Lemaire wrote:
    >> In the answer to question 4.8 I see this code (copied and pasted):
    >>
    >> -------------------------
    >> void f(ipp)
    >> int **ipp;
    >> {
    >> static int dummy = 5;
    >> *ipp = &dummy;
    >> }
    >> ...
    >>
    >> int *ip;
    >> f(&ip);
    >> -------------------------
    >>
    >> I'm confused about the two first lines. Should'nt the first one be
    >> written 'void f(**ipp)' and the second one scrapped altogether?

    >
    > ITYM `void f(int **ipp)'.


    IID (Indeed I Did).

    >> If not, I don't understand how the above can be legal.

    >
    > Question 11.3 has a useful hint, and 11.4 is worth
    > a look, too.


    OK, I understand now. I'm not used to reading the old style syntax and
    would have never thought it was simply that.

    Thanks for pointing me in the right direction.

    JFL
    --
    Jean-François Lemaire
     
    Jean-François Lemaire, Jan 4, 2008
    #3
  4. Jean-Francois Lemaire <> writes:
    > In the answer to question 4.8 I see this code (copied and pasted):
    >
    > -------------------------
    > void f(ipp)
    > int **ipp;
    > {
    > static int dummy = 5;
    > *ipp = &dummy;
    > }

    [...]

    That's an old-style function definition; it predates the ANSI
    standard, but it's still permitted, even in C99.

    What I don't know is why the FAQ still uses it here. I see no good
    reason not to use a prototype. Probably it's just an oversight. I've
    sent e-mail to Steve Summit.

    (Sorry about mangling your name; this environment isn't handling
    non-ASCII characters very well.)

    --
    Keith Thompson (The_Other_Keith) <>
    [...]
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Jan 4, 2008
    #4
  5. On Friday 4 January 2008 21:26, Keith Thompson wrote:

    > Jean-Francois Lemaire <> writes:
    >> In the answer to question 4.8 I see this code (copied and pasted):
    >>
    >> -------------------------
    >> void f(ipp)
    >> int **ipp;
    >> {
    >> static int dummy = 5;
    >> *ipp = &dummy;
    >> }

    > [...]
    >
    > That's an old-style function definition; it predates the ANSI
    > standard, but it's still permitted, even in C99.
    >
    > What I don't know is why the FAQ still uses it here. I see no good
    > reason not to use a prototype. Probably it's just an oversight. I've
    > sent e-mail to Steve Summit.


    Yes, this can be confusing for new users of the language, the intended
    audience of the FAQ, who are less likely to have encountered such a
    function definition. At least it was confusing for me.

    > (Sorry about mangling your name; this environment isn't handling
    > non-ASCII characters very well.)


    No excuse needed, I can assure you.

    JFL
    --
    Jean-François Lemaire
     
    Jean-François Lemaire, Jan 4, 2008
    #5
    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. Enrico Palazo
    Replies:
    8
    Views:
    412
    Enrico Palazo
    Jan 12, 2004
  2. suzy
    Replies:
    3
    Views:
    348
  3. Victor Bazarov

    FAQ and our desire to answer questions

    Victor Bazarov, Feb 2, 2004, in forum: C++
    Replies:
    4
    Views:
    351
    E. Robert Tisdale
    Feb 3, 2004
  4. Stephan Kämper
    Replies:
    2
    Views:
    209
    Stephan Kämper
    Jan 24, 2005
  5. Jake Barnes
    Replies:
    2
    Views:
    91
    Thomas 'PointedEars' Lahn
    Apr 12, 2009
Loading...

Share This Page