J
John Hanley
I am getting some inconsistencies with mktime().
I allocate memory for my struct tm early in my program, and assign only
*some*
of the member variables.
t->tm_sec=s;
t->tm_min=m;
t->tm_hour=h;
t->tm_mday=d;
t->tm_mon=mo-1;
t->tm_year=y-1900;
I leave out tm_wday, tm_yday, & tm_isdst.
after this I free(t).
I examine the values in my debugger. When I allocate the memory, all the
values are 0. When I call mktime(t), the function changes my tm_hour
(adds an hour) and I get a certain value returned.
Why is it changing the hour?
In another part of my program (a totally different function), I allocate
memory for my struct tm (a different local struct tm), I read in data
(exactly the same values as in my other function), again I don't fill in
tm_wday, tm_yday, & tm_isdst. There seems to be some residual values
(not 0 this time)from when I allocated the memory and didn't initialize
the 3 fields.This time when I call mktime(t), it doesn't change my
tm_hour and I get a different value returned (the correct value).
Same initial values, two different calls, two different return values.
It appears mktime is trying to guess the correct date based on what I
provide.
I am thinking that perhaps whatever values happen to be in the memory
location when I allocate the memory are what are changing the values?
Should I be initializing the tm_wday, tm_yday, & tm_isdst to something?
Why is mktime() changing the hour in my struct tm?
Any suggestions?
Thanks!
John
I allocate memory for my struct tm early in my program, and assign only
*some*
of the member variables.
t->tm_sec=s;
t->tm_min=m;
t->tm_hour=h;
t->tm_mday=d;
t->tm_mon=mo-1;
t->tm_year=y-1900;
I leave out tm_wday, tm_yday, & tm_isdst.
after this I free(t).
I examine the values in my debugger. When I allocate the memory, all the
values are 0. When I call mktime(t), the function changes my tm_hour
(adds an hour) and I get a certain value returned.
Why is it changing the hour?
In another part of my program (a totally different function), I allocate
memory for my struct tm (a different local struct tm), I read in data
(exactly the same values as in my other function), again I don't fill in
tm_wday, tm_yday, & tm_isdst. There seems to be some residual values
(not 0 this time)from when I allocated the memory and didn't initialize
the 3 fields.This time when I call mktime(t), it doesn't change my
tm_hour and I get a different value returned (the correct value).
Same initial values, two different calls, two different return values.
It appears mktime is trying to guess the correct date based on what I
provide.
I am thinking that perhaps whatever values happen to be in the memory
location when I allocate the memory are what are changing the values?
Should I be initializing the tm_wday, tm_yday, & tm_isdst to something?
Why is mktime() changing the hour in my struct tm?
Any suggestions?
Thanks!
John