The pointer cast is completely unnecessary. If your program appears to work, it's an unlucky coincidence. (I say "unlucky" because it means the error is not being diagnosed.)
localtime()
takes an argument of type const time_t*
, not clock_t*
. time_t
and clock_t
are distinct types, used for different purposes, even though they might happen to be defined in the same way in some particular implementation.
Change the definition of now
to:
time_t now;
and call localtime
like this:
mac_time = localtime(&now);
Any cast, especially a pointer cast, should be viewed with suspicion. Casts are too often used to silence compiler warnings, when the real solution is to fix your code so things are declared with the correct type in the first place.
As for the question you're asking -- well, it doesn't matter much, since the code is fundamentally incorrect. This:
mac_time = localtime((const long *)&now)
takes the address of now
(which, in your code, is of type clock_t*
) and converts it to const long*
. Since localtime
expects an argument of type const time_t*
, and apparently time_t
is defined as long
on your implementation, this appears to work.
This:
mac_time = localtime(&(const long *)now);
takes the value of now
(which at this point has not been initialized) and converts it to a const long*
; in other words, it takes a garbage numeric value and converts it to a pointer. It then attempts to take the address of that pointer -- but since it's a pointer value, not a pointer object, it has no address. The above is a compile-time error. (I'd expect your compiler to treat this as a fatal error, not just a warning.)
But forget all that. Just declare your objects to be of the correct types in the first place, and you won't have to worry about casts.
(There are cases where casts, even pointer casts, are necessary and appropriate, but not for what you're trying to do here.)