TITLE: evaluating &*e (Newsgroups: comp.std.c++, 4 Jan 99) FVALI: fvali@biotrack.com >> In C (my reference is the C9x draft) the expression &*E is equivalent >> to E even if E is a null pointer, i.e., neither the operand of *, nor of >> & is evaluated. >> >> I found no evidence that this expression is well-defined in Standard C++. >> >> Thus the following fragment is well defined C code but not C++: >> >> struct A { }; >> >> struct A* ap1 = 0; >> struct A* ap2 = &*(ap1); >> // assert( ap2 == 0 ); >> >> Why is this so? What is the harm in defining this behavior as is done >> for C (C9x atleast, I do not have access to a C89 std). From: Steve Clamage > Allowing &*p to have meaning when p is null requires a special > case in the semantics and associativity of the operators. Without > the special case, the meaning is &(*p), which is undefined for > a null pointer. > > In C, you can add the language wart that the "&" and "*" cancel > each other out, in effect mandating a compiler optimization. > > In C++, the situation is not so straightforward. Either or both of > the operators might be overloaded. If so, the functions must > be called unless the compiler can prove they have no side effects. > > As a further note, there is no special case in C89, which was > the only C standard in effect when the C++ standard was under > development. For that matter, C89 still is the only C standard > in effect, since C9X is only in the CD1 stage.