04-29-2010 08:05 AM
I found a lot of problems with the ANSI C calendar functions mktime(), localtime() and gmtime() in CVI 2009 running under WinXP.
Here is my code, with comments explaining what happens.
time_t now, myDate; struct tm *lt, *gmt, myTm; memset(&myTm, 0, sizeof(myTm)); //zeroise the tm struct myTm.tm_mday = 1; //because tm_mday field is 1-based myTm.tm_year = 110; // 2010 myDate = mktime(&myTm); /* in the variable window, I see that "myDate" has the right value */ now = time(&now); /* in the variable window, I see that "now" has the right value */ lt = localtime(&now); /* in the variable window, I see that "lt" has the WRONG value. It is the UTC time corresponding to "myDate", not a local date */ gmt = gmtime(&now); /* in the variable window, I see that "gmt" has the WRONG value. It is the same address as "lt", and so is the UTC time corresponding to "myDate" */
Is this an expected behaviour?
Or is there a bug in these functions implementation?
04-29-2010 09:19 AM
Hey Vix -
Thanks for reporting this. It's unclear from your post, but as I looked at this, it seemed the values were only incorrect in the debugging windows such as the Variables window, and not during runtime. I've reported this with bug ID 223736.
Fortunately, the work-around should be pretty simple for you. This bug appears to be related to the new extended debugging information feature of CVI 2009. If you disable this feature (Options»Environment»Enable extended Variables/Watch window displays) for one debugging session, things should display correctly in the debugger. After they have displayed correctly once, you should be able to re-enable the feature and continue to see things display correctly. Let me know if your experience differs from mine.
NickB
National Instruments
04-29-2010 09:51 AM - edited 04-29-2010 09:51 AM
nickb wrote: it seemed the values were only incorrect in the debugging windows such as the Variables window, and not during runtime.
Also the Memory window shows wrong values...
Fortunately, the work-around should be pretty simple for you. This bug appears to be related to the new extended debugging information feature of CVI 2009. If you disable this feature (Options»Environment»Enable extended Variables/Watch window displays) for one debugging session, things should display correctly in the debugger.
I tried this, and it works.
The only problem is that localtm() and gmtime() return the same address, so the second function overwrites the struct filled by the first
After they have displayed correctly once, you should be able to re-enable the feature and continue to see things display correctly.
Unfortunately, re-enabling this feature the wrong values are shown...
04-29-2010 10:23 AM
The fact that the two functions return the same pointer is per the ANSI C 89 specification - section 7.23.3 (page 341 on that link).
It looks like you are right that the display of these structures is a little more finicky than just enabling and disabling the option. I'll be sure to note that in the bug report.
NickB
National Instruments
04-29-2010 10:34 AM
The fact that the two functions return the same pointer is per the ANSI C 89 specification - section 7.23.3 (page 341 on that link).
Thank you very much for this information: I think it could be useful adding this advice to the CVI help file for the affected functions.
04-29-2010 10:59 AM
Vix -
I agree that is a hole in our documentation. I have filed a report to add this information to the documentation.
NickB
National Instruments