A function type (lvalue) can be converted to a pointer to function (rvalue).
int func();
int (*func_ptr)() = func;
But from (4.1/1)
An lvalue (3.10) of a non-function, non-array type T can be converted
to an rvalue.
Does it mean that a lvalue to rvalue conversion is not done on functions? Also, when an array decays to pointer doesn’t it return a rvalue which is a pointer?
Functions are lvalues. A pointer to a function (a data type) can be
either; if you give it a name, it’s an lvalue; otherwise, it’s not
(roughly speaking). Pointers to functions obey all of the usual lvalue
to rvalue conversion rules. For simple types like the basic types or
pointers, the lvalue to rvalue conversion basically means reading the
variable.
Note that there is an implicit conversion of function to pointer to
function, and that the
()operator works on both functions andpointers to functions, so the last two lines could be written:
As always, the result of the conversion is an rvalue (unless the
conversion is to a reference type). This is also the case when an array
is implicitly converted to a pointer; both arrays and functions can only
exist as lvalues, but they both implicitly convert to a pointer,
which is an rvalue. But that pointer can be used to initialize a
variable of the appropriate pointer type; such variables are lvalues.