Changes between Version 25 and Version 26 of CodeStyle


Ignore:
Timestamp:
02/23/18 17:33:41 (15 months ago)
Author:
selvanair
Comment:

See commit 9ba36639abcac4367c8227d2dd87b18fb56267c4

Legend:

Unmodified
Added
Removed
Modified
  • CodeStyle

    v25 v26  
    8585POSIX specifies that time_t is an integer type but does not specify its size.  The underlying type might be "int", "long" or "long long", some systems might make it unsigned too.  This makes it hard to portably print time_t values using printf-like APIs, as a mismatch between the format string and the actual time_t size can lead to crashes or bogus representations.
    8686
    87 The safest way is to print time_t values as long long, which is at least 64 bits wide and thus does not cause y2038 problems.
     87The safest way is to print time_t values after casting to int64_t and using PRIi64 as format specifier. Casting to a 64 bits wide int avoids y2038 problems and "PRIi64" is preferred over %lld as the latter is not supported in the windows runtime targeted by mingw.
    8888
    8989Similarly, POSIX specifies suseconds_t as a signed integer, but does not specify its size.  Casting it as a long is enough.
     
    9292  struct timeval now;
    9393  gettimeofday(&now, NULL);                                                                                                                                                                                   
    94   printf("%lld.%06ld\n", (long long)now.tv_sec, (long)now.tv_usec);
     94  printf("%"PRIi64".%06ld\n", (int64_t)now.tv_sec, (long)now.tv_usec);
    9595}}}
    9696