#Lost at C (Again!)
17-Mar-87 20:27:16
Sb: #59327-#Lost at C (Again!)
Fm: Don Curtis/SYSOP 76703,4321
To: Richard Rae/SYSOP 76703,4253
Rick,
As to why localtime() is a pointer rather than a void accepting the
pointer to a tm struct as one of it's arguments—I don't know, other than
that's the way it was written. I can envision a few reasons why…perhaps you
want to fill out several tm structs and a single call is sufficient, perhaps
you only want to grab the minutes value and don't want to carry even a local
structure around (saves memory) so you just use
minutes = localtime(&clock)->tm_min;
and you're done with it. More than likely, it's faster that way also.
I suggested the second method as it will always be correct, but in your
instant case, either is correct. Again, I presume a temporary structure is set
up in memory which localtime() points to…local to that particular module
only. If you had pointer as a global variable and attempted to use it in
another module (or perhaps even in another function) you might get wrong
results. Again, this presupposes that a local structure is created a pointer
to it being returned via localtime(). Now, if localtime() returns a pointer to
the system structure…the one that is always there running under AmigaDOS,
then the use of pointer is correct. You grab the address of the system
structure once, and from there on use indirect reference to it via
pointer->element. I don't know if this is a dynamic structure (that is, if the
values in it change as time changes), but if that is the case, then the fact
that localtime() returns a pointer to it, makes absolute sense.
It would then "find" the system structure, and from there on, you'd
refer to via indirection and always have the correct time and could update an
on-screen clock (or whatever) based on the value changing once a minute.
Don