Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c    |    Meh, in C you gotta define EVERYTHING    |    243,242 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 242,786 of 243,242    |
|    James Kuyper to Andrey Tarasevich    |
|    Re: printf and time_t    |
|    05 Jan 26 07:50:37    |
   
   From: jameskuyper@alumni.caltech.edu   
      
   On 2026-01-05 03:17, Andrey Tarasevich wrote:   
   > On Sun 1/4/2026 11:19 PM, Kenny McCormack wrote:   
   >> The question is: How can you reliably printf() a time_t value?   
   >> What conversion spec should you use?   
   >   
   > You can't. As far as the language is concerned, `time_t` is intended to   
   > be an opaque type. It has to be a real type, ...   
      
   In C99, it was only required to be an arithmetic type. I pointed out   
   that this would permit it to be, for example, double _Imaginary. I like   
   to think that my comment may have been responsible for the fact that   
   C2011 specified that it must be real.   
      
   > ... so it is either an integer   
   > of a plain floating-point type. But other than that nothing is known   
   > about it. There's really no point in printing it.   
   >   
   > If you still want to, you can do it in some implementation-specific way.   
   > Which still immediately means that you can't do it "reliably", if I   
   > understand what you mean correctly.   
      
   if(1/(time_t)2)   
   { // time_t is a floating point type)   
    prrintf("%lg", (long double)t);   
   }   
   else if(0 < (time_t)-1)   
   { // time_t is an unsigned integer type   
    printf("%ju", (uintmax_t)t);   
   }   
   else // time_t is a signed integer type   
    printf("%jd", (intmax_t)t);   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca