I didn't see any resolution to this in the last couple digests, so at risk
of opening a raw wound, I'd like to add my two cents and a piece of sample
code...

I first encountered this problem when trying to code something that
required yesterday's date.. so I decided the best way to do this was to
take the return value from TimGetSeconds, subtract a day's worth of
seconds, and feed that result to TimSecondsToDateTime.. the first pass of
code looked like this:

DateTimeType dateTime;
TimSecondsToDateTime((TimGetSeconds() - (60 * 60 * 24)), &dateTime);

Now, peculiarly enough.. this was not giving me the right answer.. so I
changed it a little:

DateTimeType dateTime;
ULong secs = TimGetSeconds() - (60 * 60 * 24);
TimSecondsToDateTime(secs, &dateTime);

And the answer still wasn't right.. so I tried this (note the variable name
change.. I was getting silly since it looked to me like the code couldn't
do simple arithmetic all of a sudden):

DateTimeType dateTime;
ULong adaysworthofsex = 60 * 60 * 24;
ULong sex = TimGetSeconds();
sex -= adaysworthofsex;

Ok, now I was confused.. but only for a moment.. tracing the above code in
the debugger, I found the value assigned to adaysworth of sex was only
20864 (ok, I'm trying to remember off the top of my head, but it was close
to that number). A quick check showed that the actual value 86400 - 20864
was 65536 ... hmmm.. curiouser and curiouser.. so deciding to do it the way
I probably should have in the first place (and just plugged 86400 in
directly instead of adding all of that compile time/run time depending on
optimization nonsense), I had the completed code:

ULong sex;
ULong adaysworthofsex = 86400; // 60 secs/min * 60 mins/hr * 24 hrs/day
char yest[11];
sex = TimGetSeconds();
sex-= adaysworthofsex;
TimSecondsToDateTime (sex, &dateTime);
StrPrintF(yest, "%02d/%02d/%d", dateTime.month, dateTime.day, dateTime.year);

So, bottom line.. why does the compiler do this? It assumes integer values
for the constants even though its being assigned to a long? What's up with
that?

Bradly J. Barton - [EMAIL PROTECTED]
Jenies Technologies Incorporated
(972) 602-1835
JTI.net
PalmInHand.com


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to