Changes between Version 22 and Version 23 of CodeStyle


Ignore:
Timestamp:
11/16/17 15:08:56 (6 years ago)
Author:
j.ca
Comment:

Document how to print time_t values

Legend:

Unmodified
Added
Removed
Modified
  • CodeStyle

    v22 v23  
    7878
    7979This makes the intent immediately clear to the reader / reviewer.
     80
     81= Portability concerns =
     82
     83== Printing time_t values ==
     84
     85POSIX 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 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. The safest way is to print those values as long long, which is at least 64 bits wide.
     86
     87{{{#!c
     88time_t now = time(NULL);
     89printf("%lld seconds\n", (long long)now);
     90}}}
    8091
    8192= Crustify rules =