The "rules" are the C language rules. They will not appear in any headers.
NumOfDays = (T2 - T1) / (24L * 3600L) + 1L
should work.
It is not a matter of size (i.e., sizeof) it's a matter of type. It just so
happens that (generally) the higher the precision the numeric type, the
larger it is.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Danko Radic
Sent: Friday, February 25, 2000 7:53 AM
To: Palm Developer Forum
Subject: RE: Little C or compiler question
Thanks! In which file/header or whatever are such rules defined? I'd like
to print it out in order to prevent such errors.
I've even tried
NumOfDays=(T2-T1)/(ULong)(24*3600)+1;
but with the same (wrong) result. It seems that for a*b compiler takes
sizeof(a), then sizeof(b) and result is truncated to
Max{sizeof(a),sizeof(b)}.
Is it matter of compiler or PalmOS or C in general?
Rgds,
-DR
On Fri, 25 Feb 2000, Al Cilcius wrote:
> The type of the result of (24 * 3600) is int. On PalmOS this is 16bits in
> size. The result can not fit in 16bits so the high-order bits are
truncated
> leaving you with the lower 16bits which are 0x5180 == 20864decimal.
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Danko Radic
> Sent: Friday, February 25, 2000 3:52 AM
> To: Palm Developer Forum
> Subject: Little C or compiler question
>
>
> (CW R5 + 2 patches, Win95)
>
> I have:
>
> ULong T1,T2,NumOfDays;
>
> Why does:
>
> NumOfDays=(T2-T1)/86400+1;
>
> give correct result and
>
> NumOfDays=(T2-T1)/(24*3600)+1;
>
> doesn't?
> T1, T2 are times in seconds, and when they differ for 1.999 days, 1st
> operation gives correct NumOfDays=2, but 2nd gives result NumOfDays=9.
> If it is automatic casting problem, where can I find these rules?
>
> Rgds,
>
> -DR
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palm.com/devzone/mailinglists.html
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palm.com/devzone/mailinglists.html
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palm.com/devzone/mailinglists.html
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html