OK, kept getting “crazy talk” from my struct tm’s. Finally figured out they aren’t empty when they are initialized…inside the “main” function - had to move them out. Why does it matter where they are initialized??
Instances of structs in Objective-C are not always guaranteed to be initialized automatically. You just have to remember this and proceed with caution.
For example:
struct String
{
unsigned int length;
char * value;
};
s is not initialized:
void bar ()
{
struct String s;
unsigned int len = s.length; // len == ?
char * value = s.value; // value == ?
}
s is initialized because it is in global scope:
struct String s;
void bar ()
{
unsigned int len = s.length; // len == 0
char * value = s.value; // value == 0
}
s is initialized because it is static:
void bar ()
{
static struct String s;
unsigned int len = s.length; // len == 0
char * value = s.value; // value == 0
}
s is initialized explicitly:
void bar ()
{
struct String s = {6, "jibber"};
unsigned int len = s.length; // len == 6
char * value = s.value; // value == "jibber"
}
s is initialized explicitly:
void bar ()
{
struct String s;
memset (&s, 0, sizeof (s));
unsigned int len = s.length; // len == 0
char * value = s.value; // value == 0
}