Search code examples
c++arraysdereference

C++: &*A is not equivalent to A for array declaration?


The C standard 6.5.3.2 Address and indirection operators (3) says:

"The unary & operator returns the address of its operand. If the operand has type ‘‘type’’, the result has type ‘‘pointer to type’’. If the operand is the result of a unary * operator, neither that operator nor the & operator is evaluated and the result is as if both were omitted, except that the constraints on the operators still apply and the result is not an lvalue."


"83) Thus, &*E is equivalent to E (even if E is a null pointer), and &(E1[E2]) to ((E1)+(E2)). It is always true that if E is a function designator or an lvalue that is a valid operand of the unary & operator, *&E is a function designator or an lvalue equal to E. If *P is an lvalue and T is the name of an object pointer type, *(T)P is an lvalue that has a type compatible with that to which T points."

So if I understand well, &*E is behave as if we would delete &*. However,

#include <cstdio>
#include <typeinfo>

int main()
{
    float A[2];
    printf( "name: %s\n", typeid( &*A ).name());
    printf( "name: %s\n", typeid( A ).name());
    getchar();
    return 0;
}

will give:

name: Pf
name: A2_f

So they aren't the same.

What is wrong? What is I'm misunderstanding? I would appreciate your help, Thanks.


Solution

  • These aren't the same.

    The &*A gives you the address of the 1st element in the A array as a decayed pointer float*, and A is a particular array type as declared with float A[2].