> #define kTimeLimit 30 * 24 * 60 * 60
> ULong secs;
> secs = kTimeLimit;
The preprocessor expands the last line to:
secs = 30 * 24 * 60 * 60;
All of the literals are ints because they don't have "U" (for unsigned) or "L" (for
long) on the end. So the multiplication is done with ints, resulting in overflow. Then
the assignment casts the resulting int into a ULong, probably sign extending it in the
process. To fix this, just change your #define as follows:
#define kTimeLimit (30UL * 24 * 60 * 60)
You could put "UL" after each number, but it's not necessary. The parens around it are
a good idea in general, but not strictly necessary in this case.
The compiler may choose to do the multiplication at compile time or leave it to
run-time. In practice, it'll probably be done at compile time.
-
Danny Epstein * mailto:[EMAIL PROTECTED]
Applied Thought Corporation * http://www.appliedthought.com
Flytrap for PalmOS * http://www.appliedthought.com/flytrap