Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Function pointer in argument list

Reply
Thread Tools

Function pointer in argument list

 
 
hectorchu@gmail.com
Guest
Posts: n/a
 
      03-26-2009
Does anyone know whether the (*) is optional around the function
pointer name when it is part of an argument list, e.g.

int f(int fn(int))
{
return fn(5);
}

?
 
Reply With Quote
 
 
 
 
hectorchu@gmail.com
Guest
Posts: n/a
 
      03-26-2009
Thank you for all your contributions. The C99 reference seems to
answer my question conclusively.
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      03-26-2009
Richard Heathfield <> writes:
> said:
>> Does anyone know whether the (*) is optional around the function
>> pointer name when it is part of an argument list, e.g.


You mean parameter list, not argument list. An argument list is the
list of expressions in a function call.

>> int f(int fn(int))
>> {
>> return fn(5);
>> }
>>
>> ?

>
> Believe it or not, it *is* optional. 3.2.2.1 of C89 reads in part:
> "A function designator is an expression that has function type.
> Except when it is the operand of the sizeof operator /25/ or the
> unary & operator, a function designator with type ``function
> returning type '' is converted to an expression that has type
> ``pointer to function returning type .''"


Yes, but that's not the section that says it's optional. The text you
quoted says that the "*" is optional in a function call, not in a
function declaration.

The relevant paragraph is C99 6.7.5.3p8:

A declaration of a parameter as "function returning _type_" shall
be adjusted to "pointer to function returning _type_", as in
6.3.2.1.

> And I don't mind admitting that my initial reaction was "no". But I
> was wrong.


--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      03-26-2009
Richard Heathfield <> writes:

> Keith Thompson said:
>
>> Richard Heathfield <> writes:

> <snip>
>>>
>>> Believe it or not, it *is* optional. 3.2.2.1 of C89 reads in
>>> part: "A function designator is an expression that has function
>>> type. Except when it is the operand of the sizeof operator /25/
>>> or the unary & operator, a function designator with type
>>> ``function returning type '' is converted to an expression that
>>> has type ``pointer to function returning type .''"

>>
>> Yes, but that's not the section that says it's optional. The text
>> you quoted says that the "*" is optional in a function call, not
>> in a function declaration.
>>
>> The relevant paragraph is C99 6.7.5.3p8:
>>
>> A declaration of a parameter as "function returning _type_"
>> shall be adjusted to "pointer to function returning _type_",
>> as in 6.3.2.1.

>
> Oops, nice catch. Thanks, Keith. The corresponding C89 quote is in
> 3.7.1, with the same wording, modulo the capital A and the
> cross-ref.


If it helps reduce the surprise factor, this is somewhat analogous to
the treatment of parameters that look as if they have an array type.

I too, only came across this very recently due to a typo and a
preference for keeping *s out of typedefs. I'd written:

typedef int func(int);

int some_function(func f) /* forgot the * by accident! */
{...}

and only found out that I should have been surprised that it worked
some time later when fixing something else! On the other hand, I
would not have been surprised that

typedef int vector[3];

int other_function(vector v) {...}

makes 'other_function' of type 'int(int *)' so there is some
similarity. Of course, the similarity stops when you *do* add the *.
It has no effect on 'some_function' but changes the type of
'other_function' to be 'int(int (*)[3])'.

--
Ben.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable argument function as a parameter of a variable argument function AikidoGuy C Programming 11 11-21-2011 10:43 PM
function argument dependent on another function argument? Reckoner Python 11 01-19-2009 03:31 AM
Passing pointer to template function as argument to pointer to template function Vijai Kalyan C++ 4 11-08-2005 07:53 PM
How to pass variable argument list to another function w/ variable argument list? Ben Kial C Programming 1 11-15-2004 01:51 AM
'dynamic' function pointer argument list Bernhard C Programming 6 07-16-2004 12:43 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57