Can the time_t time(time_t *t)
function ever return failure if the argument passed is always NULL?
If the call is time(NULL)
, do we still need to check for the return value?
The only documented error code is EFAULT, which relates to the pointer being invalid.
time(NULL) returns the number of seconds elapsed since 00:00:00 hours, GMT (Greenwich Mean Time), January 1, 1970.
If you make the function to do some operation , return 0 for success , -1 for failed, and set errno to appropriate value so that the caller could check it to know the detail of failure. Sometimes people also use different return values to mean different failures.
null will cause the time conversion operation to fail, but still creates a time object. In the action immediately following the Convert time zone action, set the Configure run after to run after success and failure. Do this for every action that comes after a Convert time zone action. Doing this will fix all the issues you have been having.
Speaking purely as an editor, I acknowledge that "failing to reject the null hypothesis" is cringe-worthy. "Failing to reject" seems like an overly complicated equivalent to accept. At minimum, it's clunky phrasing. But it turns out those rough-and-ready statisticians in the Nulls Angels have good reason to talk like that.
In the action immediately following the Convert time zone action, set the Configure run after to run after success and failure. Do this for every action that comes after a Convert time zone action.
The C++ committee could have let new return a null pointer on an allocation failure, but every constructor that used new for internal memory would have to detect the failure and turn it into an exception anyway. So having new throw by default simplifies everyone's code.
Yes. time
has a documented may fail case:
The time() function may fail if:
[EOVERFLOW] The number of seconds since the Epoch will not fit in an object of type time_t.
Source: http://pubs.opengroup.org/onlinepubs/9699919799/functions/time.html
Expect this to happen in practice in about 22 years, no sooner, and not on 64-bit systems or 32-bit ones that utilize a 64-bit time_t
.
Also, the presence of any shall fail or may fail cases also allows for implementation-defined errors, though their existence would be a serious quality-of-implementation flaw.
EFAULT
is a non-issue/non-existent because it only happens when your program has undefined behavior.
So despite all this, in the real world, time
is not actually going to fail.
Can time(NULL) ever return failure?
No. C standard says that
C11: 7.27.2.4:
The time function returns the implementation’s best approximation to the current calendar time. The value
(time_t)(-1)
is returned if the calendar time is not available.
I've checked on RHEL, SLES and UBTU; the man 2 page yields the same (relevant) thing:
time() returns the time since the Epoch (00:00:00 UTC, January 1, 1970), measured in seconds.
If t is non-NULL, the return value is also stored in the memory pointed to by t.
Anyway, going back to the original questions
Q0: Can the time_t time(time_t *t)
function ever return failure if the argument passed is always NULL?
Q1: If the call is time(NULL), do we still need to check for the return value?
Q2: The only documented error code is EFAULT
, which relates to the pointer being invalid.
NULL
, so there's no problem.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With