Skip to Content.
Sympa Menu

c-semantics - [C-Semantics] &*Exp

c-semantics AT lists.cs.illinois.edu

Subject: C Semantics in K Framework

List archive

[C-Semantics] &*Exp


Chronological Thread 
  • From: Chucky Ellison <celliso2 AT illinois.edu>
  • To: c-semantics AT cs.illinois.edu
  • Subject: [C-Semantics] &*Exp
  • Date: Tue, 17 Jan 2012 17:25:40 -0600
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/c-semantics>
  • List-id: C Semantics in K Framework <c-semantics.cs.illinois.edu>

There is an interesting little exception in the semantics of & if the
operand is a deref (*). The C11 (and C99) standards say (6.5.3.2)
"the result is as if both were omitted, except that the constraints on
the operators still apply and the result is not an lvalue".
Essentially, for E of pointer type, &*E is equivalent to E, even if E
is a null pointer.

I was writing some tests for this for kcc and hit on the following expression:
&(&(*(*(void**)NULL))) == (void**)NULL
I'd argue that based on the standard, &(&(*(*(void**)NULL))) is "as
if" it were &(*(void**)NULL), which is "as if" it were (void**)NULL.

It seems to me that this expression is defined and is true. However,
GCC (4.1.2) and Clang (3.0 (trunk 132915)) don't seem to handle this
case. GCC gives "error: invalid lvalue in unary '&'" and Clang gives
"error: address expression must be an lvalue or a function
designator". I think these are both incorrect errors, because the
constraints for the & operator allow another case:
(6.5.3.2:1) "The operand of the unary & operator shall be either a
function designator, the result of a [] or unary * operator, or an
lvalue that designates an object". GCC and Clang don't seem to
support the case "the result of a [] or unary * operator".

For what it's worth, ICC (11.1) accepts the expression with no
warnings and evaluates to true.

What do you all think about this example? Do more recent versions of
GCC run it?

-Chucky




Archive powered by MHonArc 2.6.16.

Top of Page