Question regarding to how the struct tm works


#1

Hi,

as lots of others have already stated, BNR Objective-C Programming truly is a great book. So far the only book on programming in general that has kept me reading past page 10 or so. Huge thanks!

Now to my question:

Working with addresses (and pointers for that matter) is a thing I do not quite understand well. I have read that chapter twice but I’m hoping it will clear up by using the techniques a lot over the coming examples and challenges. And this is also where my problem with the struct lies.
I use the function localtime_r() to assign the value that is stored at the location of secondsSince1970 to where the value of the struct now is stored. But then how do the members of the struct now (e.g. now.tm_min or now.tm_hour) understand that value. There has to be some kind of conversion/division going on somewhere? Is that defined for any struct following the tm blueprint somewhere? Or is there something I’m not quite getting?

The other question would be why the function localtime_r() is even necessary. Couldn’t I just somehow assign those values to each other without the use of a function at all? It feels like this is something I’d do again somewhere in the future whilst not working with something time-specific at all. Why should I not be able to do that without calling a function that - judging by its name - clearly is only needed when handling time?

Thank you very much in advance!

EDIT: Unless of course the function localtime_r() is responsible for filling the members of the struct with their correct values. If this is true this solves both questions. I’ll just leave this post here then in case anybody else ever comes along with the same question.


#2

You have it exactly right at the very end: localtime_r() is responsible for filling the members of the struct with their correct values.


#3

Ah, thanks! Now I can be sure and go on.

It seems I had both problems completely separated in my head and only came across seeing both together when I had written them down. :wink:


#4

Thanks for stating your explanation [color=#0000FF]killankoe[/color]! I wonder how many times I would have had to read that sentence on p. 67 before it would sink in?! DUH!!! :unamused: