: On Tue, 16 Sep 2003 08:44:02 +0800, Roy Yao wrote:
:
: > Hello Keerthi,
: >
: > Thanks for your enthusiasm.
: >
: > My email to you was rejected by your mail server, so I reply you here.
You(Roy) are supposed to reply here.
: > In this expression, what confused me is how the compilers (or ANSI C)
: > determine the combination of operator sizeof, (type) and *.
: >
: > In my opion it should equal to expression "sizeof( (int)(*p) )". The
: > reason is that operator sizeof, (type) and * have the same
: > precedence, and they combine from right to left. But the compilers prefer
: > "(sizeof(int))* (p)".
: >
: > Now can you give me a convictive explain from the precedence and
: > combination order of operator ?
:
: I told you in my other post, that's NOT the (type) operator! (type) is the
: /operand/ of sizeof.
You are right, but he wants to know why.
Some relevent production rules:
unary-expression:
postfix-expression
++ cast-expression
-- cast-expression
unary-operator cast-expression
sizeof unary-expression
sizeof ( type-id )
new-expression
delete-expression
unary-operator: one of
* & + - ! ~
The expression in question:
sizeof (int) * p
'(int) * p' isn't a unary-expression, because it is not starting
with ++, --, *, &, +, -, !, ~, sizeof, new, or delete, and it is
not a postfix-expression (believe me!). So a compiler can't parse
the expression in question as 'sizeof unary-expression'.
Regards,
tx