home bbs files messages ]

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,875 of 243,242   
   Keith Thompson to Michael S   
   Re: printf and time_t   
   07 Jan 26 04:28:05   
   
   From: Keith.S.Thompson+u@gmail.com   
      
   Michael S  writes:   
   > On Tue, 06 Jan 2026 16:29:04 -0800   
   > Keith Thompson  wrote:   
   >> Michael S  writes:   
   >> > On Tue, 6 Jan 2026 10:31:41 -0500   
   >> > James Kuyper  wrote:   
   >> >> On 2026-01-06 04:29, Michael S wrote:   
   >> >> > On Tue, 6 Jan 2026 00:27:04 -0000 (UTC)   
   >> >> > Lawrence D’Oliveiro  wrote:   
   >> >> ...   
   >> >> >> Section 7.8 of the C spec defines macros you can use so you   
   >> >> >> don’t have to hard-code assumptions about the lengths of   
   >> >> >> integers in printf-format strings.   
   >> >> >   
   >> >> > Did you ever try to use them? They look ugly.   
   >> >>   
   >> >> Which is more important, correctness or beauty?   
   >> >   
   >> > It depends.   
   >> >   
   >> > When I know for sure that incorrectness has no consequences, like   
   >> > in case of using %u to print 'unsigned long' on target with 32-bit   
   >> > longs, or like using %llu to print 'unsigned long' on  target with   
   >> > 64-bit longs, then beauty wins. Easily.   
   >>   
   >> Seriously?   
   >>   
   >> An example:   
   >>   
   >>     unsigned long n = 42;   
   >>     printf("%u\n", n);  // incorrect   
   >>     printf("%lu\n", n); // correct   
   >>   
   >> Are you really saying that the second version is so much uglier   
   >> than the first that you'd rather write incorrect code?   
   >   
   > No, I don't think that it is much uglier. At worst, I think that   
   > correct version is tiny bit uglier. Not enough for beauty to win over   
   > "correctness", even when correctness is non-consequential.   
   >   
   > I hoped that you followed the sub-thread from the beginning and did not   
   > lost the context yet.   
      
   The context to which I replied was you favoring beauty over   
   correctness and using "%u" to print an unsigned long value as   
   an example.   
      
   I find it difficult to express how strongly I disagree.   
      
   >                       Which is (everywhere except LIN64)   
   >  uint32_t n = 42;   
   >  printf("n = %u\n", n);  // incorrect   
   >  printf("n = " PRIu32 "\n", n); // correct   
      
   printf("n = %lu\n", (unsigned long)n); // also correct   
      
   > or on LIN64   
   >  uint64_t n = 42;   
   >  printf("n = %llu\n", n);  // incorrect   
   >  printf("n = " PRIu64 "\n", n); // correct   
      
   printf("n = %llu\n", (unsigned long long)n); // also correct   
      
   As far as I'm concerned, the incorrect versions aren't even worth   
   considering.   
      
   > Here in my book beauty wins by landslide.   
   > Although really it is not beauty wins. It's ugliness loses.   
      
   I don't think much of your book.   
      
   [...]   
      
   > I am happy that in practice your position is not too different from my   
   > position. It's just that irresistible urge of you to defend "right"   
   > things in NG discussions that creates an appearance of disagreeing.   
      
   I don't know how you reached the conclusion that our positions are   
   "not too different".  As far as I can tell, they are completely   
   different.  You would knowingly write incorrect code.   
      
   Given two alternative pieces of code, I prefer the prettier one   
   if both are correct (and that is of course a matter of taste).   
   But if one is incorrect, it doesn't matter how pretty it is.   
      
   --   
   Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com   
   void Void(void) { Void(); } /* The recursive call of the void */   
      
   --- 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