(e-mail address removed) wrote On 05/03/06 18:17,:
Thank you for learning to quote context; it makes
things much easier. One tiny addition: remember to
include attributions when you quote, so one can tell
who's being quoted. See the "milhous ... wrote" line
above? That's what's wanted. Read some of the other
threads in this and other newsgroups, and you'll get
an idea of the style.
Back to our story: I wrote
A cast operator "binds more tightly" than the division
operator, so `(int)b / c' means `((int)b) / c' and not
`(int)(b / c)'. [...]
Secondly the cast does NOT bind tighter in all cases
Consider the example
int main()
{
int a = 7;
int b = 8;
double c = 7/8;
double d = (double)7/8;
double e = ((double) 7)/8;
printf("%lf %lf %lf", c,d,e);
}
prints
0.000000 0.875000 0.875000
This example shows that the casting does not ALWAYS bind tighter.
It shows the opposite. Since d and e are identical,
the extra parentheses in e's computation made no difference:
they did not change the meaning of the expression. That
means that in d's computation, the cast binds to the 7 and
not to the quotient 7/8 (which would have been zero).
A thought: Are you using the word "cast" in the same
way the C language does? There are exactly two casts in
the code above; they are the `(double)' operators. The
conversion from int to double that takes place in c's
computation is not a cast. That conversion does, indeed,
apply to the result of the entire r.h.s. Why? Because
the `=' assignment operator[*] "binds less tightly" than
divisions and casts!
[*] Pedantry: The `=' signs above are not actually
assignment operators, but punctuation that introduces the
initializers. However, initialization takes place "as if
by assignment," and the outcome is the same.