Home/Support/Support Forum/STDIO.LIB library bug report, "_atodt" giving strange results
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

STDIO.LIB library bug report, "_atodt" giving strange results

0 votes
The aforementioned function _atodt doesn't seem to work well (DC 10.70 and 72) sometimes it returns partially random results.

In my opinion, it's because the "t" structure is not initialized.

Line 2328:
auto struct tm t;

I changed it into:
auto struct tm t = {0, 0, 0};

With tm_sec, tm_min and tm_hour initialized to zero everything is working fine.
asked Jul 22, 2013 in Rabbit by tito.brasolin New to the Community (4 points)
Hello ,  Can you explain what is the use of this function ?
Did you see this function details in any of the user''s manual?

I have tested below code
struct tm t;
   a=_atodt("7/30/2013");
  printf("%d\n",a);
  printf( "Time: %s\n", asctime( &t));  It returns 12266? I do not know what it is? can you explain?
Hello cpigilam, _atodt should return the days since 1/1/1980 given a "m/d/y" date: it is 12.264 days from "1/1/1980" to "7/30/2013", so your result is incorrect as you can see

The function is not documented (afaik)

Please log in or register to answer this question.

1 Answer

0 votes
We are not aware of an issue with this function. Can you send a small workign sample that we can ereproduce your issue?
answered Aug 13, 2013 by MargaretK Veteran of the Digi Community (545 points)
Hello MargaretK, unfortunately the issue is not easily reproducible. Afaik, if a struct that has "auto" storage is not initialized explicitly, its value is indeterminate. _atodt sets t.tm_mon, t.tm_mday and t.tm_year, but does *not* initialize t.tm_sec, t.tm_min and t.tm_hour before passing &t to mktime: that's why the final result *may* be slightly different from what we expected (e.g. if t.tm_hour == 24 mktime will normalize tm_hour to zero and add 1 to tm_tm_day).

The function may give good results most of the times, but luckily for us cpigilam tried and got a wrong result (12266 instead of 12264, see comments above)
...