Is it legal that a function pointer to "function with default arguments"?

Discussion in 'C++' started by Ajax Chelsea, Dec 2, 2003.

  1. Ajax Chelsea

    Ajax Chelsea Guest

    1,int (*f)(int a = 1);//is it legal?

    2,int (*f)(int a = 1);
    int g(int a = 2){return 0;}
    f = &g;//is it legal?
    Ajax Chelsea, Dec 2, 2003
    #1
    1. Advertising

  2. Ajax Chelsea

    Ron Natalie Guest

    "Ajax Chelsea" <> wrote in message news:...
    > 1,int (*f)(int a = 1);//is it legal?
    >
    > 2,int (*f)(int a = 1);
    > int g(int a = 2){return 0;}
    > f = &g;//is it legal?


    First, default args have no affect on function type.
    int g(int a=2)
    has type int ()(Int) NOT int()()

    Second, default args are not allowed in pointer declarations.
    8.3.6 / 3 specifically covers it (and the point is driven home by the footnote
    that specifically says "This means that default arguments cannot appear,
    for example, in declarations of pointers to functions, references to functions, or
    typedef declarations."
    Ron Natalie, Dec 2, 2003
    #2
    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. Chris Barts
    Replies:
    8
    Views:
    384
    Flash Gordon
    Jan 17, 2005
  2. Erik de Castro Lopo

    Incrementing a void pointer. Legal C99?

    Erik de Castro Lopo, Apr 13, 2006, in forum: C Programming
    Replies:
    27
    Views:
    830
    =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=
    May 22, 2006
  3. morz
    Replies:
    11
    Views:
    559
    Daniel T.
    Feb 7, 2006
  4. Replies:
    1
    Views:
    390
    Bob Hairgrove
    Mar 19, 2006
  5. Ingo
    Replies:
    2
    Views:
    565
Loading...

Share This Page