B
Ben Bacarisse
pete said:Ben said:James Kuyper wrote:
Dik T. Winter wrote:
In <[email protected]>, Kenneth
Brody wrote:
...
int main(void)
{
char new = 'z';
printf("%c %ld %c\n",new,(long)sizeof(new++),new);
return(0);
}
...
I don't see any implementation-defined behavior. Did I miss
something in my > desire to become evil?
Isn't sizeof(int) implementation defined?
"The expression ++E is equivalent to (E+=1)." (6.5.3.1p2)
Sorry - wrong operator, wrong citation - I'm not doing well this
morning. Correction:
You're apparently assuming that integer promotions must be applied to
new++. However, as footnote 48 says, "48) The integer promotions are
applied only: as part of the usual arithmetic conversions, to certain
argument expressions, to the operands of the unary +, -, and ~
operators, and to both operands of the shift operators, as specified
by their respective subclauses." Footnotes are not normative, but
footnote 48 correctly summarizes the fact, that you can verify by
reading the normative text, that those are the only locations where
the integer promotions apply. The postfix ++ operator is not one of
those locations.
I disagree. Specifically, I disagree that conversions are excluded
from the ++ operator. Not that it matters in this case, since there
is no evaluation involved, but the description of ++ (6.5.2.4 p2)
says: "See the discussions of additive operators and compound
assignment for information on constraints, types, and /conversions/
[...]" (my emphasis). The description of compound assignment is clear
that, except to the fact that the lvalue E1 is evaluated only once,
E1 += E2 behaves exactly like E1 = E1 + E2.
I think this only matters on "odd" architectures.
The integer promotions are not applied
to the left operand of the assignment operator
in the expression: (E1 = E1 + E2)
That's true, but I must be missing your point since I don't see how
that affects things. The conversions come from the + operator, not
the =.
The type of the left operand,
is the type of the assignment expression.
Again true bit again I don't see what that has to do with my point.
This is why the result of the sizeof is 1, but that matter was settled
several posts ago (at least I though it was).