Q:

Why does the following code give different answers?

I have the following code.
#include <stdio.h>
#include <time.h>

int main ()
{
  time_t rawtime;
  time_t t2 = rawtime;
  if(rawtime == t2) printf("Hi %ul %ul\n", rawtime, t2);

  return(0);
}

When this code is run, the printf gives different answers for rawtime and t2. Why is that? Could somebody please help?

A:

Here's why they don't compare as equal:

rawtime is not initialized.
Either t2 is initialized or it is not.
If t2 is initialized, then we are comparing an initialized value to an uninitialized value. There's no reason to expect these to compare as equal.
If t2 is uninitialized, we are comparing two uninitialized variables. There's no reason to expect these to compare as equal
So either way, there's no reason to expect these to compare as equal.

To expect them to compare as equal, you have to invent some odd state for t2 to be in that's, I don't even know what, initialized to an unspecified value? Uninitialized but guaranteed to compare equal to another uninitialized value? Or what?
Whatever thought process lead you to expect these to compare as equal, it is incomprehensible to me.
By the way, trying to glean this from the C standard is extremely difficult. It comes from a very obscure rule -- "If the lvalue designates an object of automatic storage duration that could have been declared with the register storage class (never had its address taken), and that object is uninitialized (not declared with an initializer and no assignment to it has been performed prior to use), the behavior is undefined."
It's much easier to just understand that it really is uninitialized than to try to understand the complex rules for when it's guaranteed to have an unspecified value and when it's not. You have to learn about trap representations and other complexity.

