In a message dated 2/26/00 4:04:15 PM Eastern Standard Time,
[EMAIL PROTECTED] writes:
> > > So, when the compiler sees
> > > (Long) 10 * 3600
> > > it multiplies an int 10 by an int 3600, then casts the result to a
> > > long. Unfortunately, the 10 * 3600 = 36000, which is too large for an
> > > int. The result is a (silent) math overflow. All you're doing is
> > > casting the wrong value to a long!
> > >
> > > If you want to override the compiler's default interpretation of
> > > literals, you have to tell it. Append an 'L' to a literal to make the
> > > compiler interpret it as long:
> > > long result;
> > > result = 10L * 3600L;
> >
> > I politely disagree.
> >
> > (Long) 10 * 3600 will typecast 10 into a 32-bit value before doing the
> > computation. Hence the result will be the same 32-bit value that you
get
> by
> > using 10L.
> >
> > -Pete
>
> And K&R disagrees with you, see page 187:
>
> An expression preceded by the parenthesized name of a data type causes
> conversion of the value of the expression to the named
> typed. The construction is call a cast.
>
> If you not sure what's going on use more parentheses, ie. ((long)10)*3600
> will do what you want, otherwise the expression is
> evaluated BEFORE the cast. Remember, the Palm is a 16-bit worl, so you
have
> to do some extra typing if you want 32 bit arithmetic.
>
> chuck
The typecast operator has higher precedence over the multiplication
operation. K&R, Second Editon, page 53 (Precedence and Order of Evaluation).
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html