Wednesday, December 10, 2014

Digest for comp.lang.c++@googlegroups.com - 13 updates in 3 topics

Belloc <jabelloc@gmail.com>: Dec 10 11:09AM -0800

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 <myfirstname@osa.pri.ee>: Dec 10 04:45PM -0600

Belloc <jabelloc@gmail.com> wrote in
> 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
Kamil Laskowski <billkozbi@gmail.com>: Dec 10 01:14PM -0800

I thought I understand fundamental rules of C++ until I wrote this simple program:
 
#include <iostream>
using namespace std;
 
#define exampleOne
 
class MyType
{
public:
MyType()
{
cout << "def ctor" << endl;
}
#ifdef exampleOne
MyType(const MyType& x)
{
cout << "copy ctor";
}

No comments: