It appears to be garbage in - garbage out, via a very obscure route. If you start off with TZ=PST8PDT export TZ call your program then you get consistent results, with the tm_zone portion of the struct set to PDT in both cases.
the man page for mktime doesn't indicate that the tm_gmtoff and tm_zone are part of it's input. So assume the values passed in are ignored. That information is supposed to be set using tzset. Both the mktime and tzset pages are somewhat unclear about who, if any of the time related routines calls tzset It appears that with TZ not set, the first call to mktime, defaults to LMT. I am assuming that some of the processing mktime does in converting the time_t value it generates back into a 'standardized' set of struct tm values it writes back to the tm struct, manages to initialize the internal TZ info to the local time zone, so by the second call to mktime it's set to PDT. A likely cause would be mktime using localtime to convert back to the tm struct. localtime is documented to follow posix behavior of acting as if tzset was called. This initializes the internal TZ data (but after the first mktime call has generated the time_t value. but before the second mktime call. that's my guess. So either set TZ first, which your program may have no control over, or call tzset before calling mktime - which will make sure the TZ data is initialized. This hand wave doesn't explain all the details but seems like a plausible explanation. steve logical american wrote: > On 1/26/2016 4:49 AM, David Barr wrote: >> I will quite happily play the straight man, here: why are `gmtoff` and >> `zone` different in `first_tm` vs `second_tm`? >> >> David > That is the $64,000 question, I want to know why the gcc compiler > changed the timezone to LMT on its own. > > _______________________________________________ > PLUG mailing list > PLUG@lists.pdxlinux.org > http://lists.pdxlinux.org/mailman/listinfo/plug > _______________________________________________ PLUG mailing list PLUG@lists.pdxlinux.org http://lists.pdxlinux.org/mailman/listinfo/plug