Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

function-to-pointer conversion

46 views
Skip to first unread message

Belloc

unread,
Dec 10, 2014, 2:09:46 PM12/10/14
to
In §5.2.2/1 (N3797) we have:

"There are two kinds of function call: ordinary function call and member function (9.3) call. A function call is a postfix expression followed by parentheses containing a possibly empty, comma-separated list of expressions which constitute the arguments to the function. For an ordinary function call, the postfix expression shall be either an lvalue that refers to a function (in which case the function-to-pointer standard conversion (4.3) is suppressed on the postfix expression), or it shall have pointer to function type."

The statement "the function-to-pointer standard conversion is suppressed on the postfix expression", doesn't make any sense to me, for AFAIK, this is the exact instance when such a conversion should occur, to convert the function name (an lvalue) to a pointer to function (an rvalue). Another obvious question: if such a conversion is suppressed, when will it be applied?

Paavo Helde

unread,
Dec 10, 2014, 5:45:53 PM12/10/14
to
Belloc <jabe...@gmail.com> wrote in
news:5cde9986-a18c-4b53...@googlegroups.com:

> The statement "the function-to-pointer standard conversion is
> suppressed on the postfix expression", doesn't make any sense to me.
> Another obvious question: if such a conversion
> is suppressed, when will it be applied?

Such a conversion occurs when you store a function to a pointer variable.
I.e.:

void f() {}
void (*x)() = f;

Without the standard conversion you would need to write &f in the last line
as far as I understand. Why the C creators were keen to save one keystroke
here I am not quite sure.

hth
Paavo

Belloc

unread,
Dec 11, 2014, 6:33:42 AM12/11/14
to
On Wednesday, December 10, 2014 8:45:53 PM UTC-2, Paavo Helde wrote:
> Belloc wrote in
I was struggling with the word "suppressed", as stated in the Standard. But it finally clicked after I read your response. And the reason seems to be so obvious, that I was missing the correct interpretation. In summary, when the Standard says:

"A function call is a postfix expression followed by parentheses containing a possibly empty, comma-separated list of expressions which constitute the arguments to the function. For an ordinary function call, the postfix expression shall be either an lvalue that refers to a function (in which case the function-to-pointer standard conversion (4.3) is suppressed on the postfix expression), or it shall have pointer to function type."

it is referring to a function name (postfix expression) followed by parenthesis, that is, a normal function call. In this case, obviously you don't need the function-to-pointer conversion and it should be suppressed, as stated. In §4.3/1 you'll find:

"An lvalue of function type T can be converted to a prvalue of type pointer to T."

where the lvalue of function type T is just the postfix expression corresponding to the function name. It doesn't include the parenthesis!

Thanks for your help Paavo.
0 new messages