Is there a difference between time_t now = time (NULL); and time_t; Time (& now) ;?

Both work correctly in my simple test code, but I would like to know if there is any real difference or any agreed preferences in coding styles.

An example of the attached code:

#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
    time_t now1, now2;
    time(&now1);
    now2 = time(NULL);

    printf("now1 = %ld\n", now1);
    printf("now2 = %ld\n", now2);

    return 0;
}

EDIT
I just saw Keith Thompson's answer - This question should probably be marked as a duplicate.

+4
source share
4 answers

There is no difference between them.

If you do this:

time_t now1, now2;
now2 = time(&now1);

Both now1and now2will have the same value.

, , Linux 2.4 64- . time , 32 ( time_t - 64-). , , , time_t, , .

+1

, : NULL, (, xor ingoing ( )), ( ), , () , , , , ( : ), .

+1

- ?

.

time_t now1, now2;
time(&now1);
now2 = time(NULL);

time_t now3 = time(NULL);, RAII , - OP 2.

?

, , . , .

+1

. , int return, - .

0

Source: https://habr.com/ru/post/1672247/


All Articles