[comp.sys.mac.programmer] GetDateTime

rg2c+@andrew.cmu.edu (Robert Nelson Gasch) (01/30/91)

I'm experiencing a strange problem when using the GetDateTime() function.
Given the following declarations and call it returns something like -26305.

long seed;
GetDateTime (&seed);
printf ("%d", seed);

The above statements return seed to be something like -26305 which is
obviously nonsense. If anybody has any idea what's wrong with this call,
please let me know as I want to use the value returned by GetDateTime()
as a seed for the random number generator.

Thanx alot --> Rob

anders@verity.com (Anders Wallgren) (01/31/91)

In article <YbdZfmW00UhWI5H1B=@andrew.cmu.edu>, rg2c+@andrew (Robert Nelson Gasch) writes:
>I'm experiencing a strange problem when using the GetDateTime() function.
>Given the following declarations and call it returns something like -26305.
>
>long seed;
>GetDateTime (&seed);
>printf ("%d", seed);
>
>The above statements return seed to be something like -26305 which is
>obviously nonsense. If anybody has any idea what's wrong with this call,
>please let me know as I want to use the value returned by GetDateTime()
>as a seed for the random number generator.
>
>Thanx alot --> Rob


pascal void GetDateTime(unsigned long *secs); 

You're passing it a long when you should be using an unsigned long -
since the toolbox uses some day in 1904 (WHY do they do this?  It
seems REALLY gratuitous to go that far back), it's already wrapped
past the maximum positive integer that can represented with a long -
you must use an unsigned long.

rg2c+@andrew.cmu.edu (Robert Nelson Gasch) (01/31/91)

The GetDateTime() problem I had was solved. The function requires
an *unsigned* integer. 

Thanx to all those who replied.
---> Rob

231b3679@fergvax.unl.edu (CS 231 section 2) (02/01/91)

anders@verity.com (Anders Wallgren) writes:

>In article <YbdZfmW00UhWI5H1B=@andrew.cmu.edu>, rg2c+@andrew (Robert Nelson Gasch) writes:
>>I'm experiencing a strange problem when using the GetDateTime() function.
>>Given the following declarations and call it returns something like -26305.
>>
>>long seed;
>>GetDateTime (&seed);
>>printf ("%d", seed);
>>
>>The above statements return seed to be something like -26305 which is
>>obviously nonsense. If anybody has any idea what's wrong with this call,
>>please let me know as I want to use the value returned by GetDateTime()
>>as a seed for the random number generator.
>>
>>Thanx alot --> Rob


>pascal void GetDateTime(unsigned long *secs); 

>You're passing it a long when you should be using an unsigned long -
>since the toolbox uses some day in 1904 (WHY do they do this?  It
>seems REALLY gratuitous to go that far back), it's already wrapped
>past the maximum positive integer that can represented with a long -
>you must use an unsigned long.

I'm a sophomore ( == wise fool), but I think the problem is that he's using
printf("%d",seed) instead of printf("%ld", seed).  Still, you will probably
get a seemingly garbage negative value, but if you use that same seed and
call something like IUDateString(seed, longDate, myDateStr255) you WILL get
the correct date back.  You are correct that one should use an unsigned long,
(and the corresponding %lu in printf()), but it doesn't make a difference in
the end.

--mike gleason