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,936 of 243,242   
   Keith Thompson to wij   
   Re: printf and time_t   
   09 Jan 26 11:27:34   
   
   From: Keith.S.Thompson+u@gmail.com   
      
   wij  writes:   
   > On Fri, 2026-01-09 at 13:49 +0100, David Brown wrote:   
   [...]   
   >> I have a lot of trouble understanding why you would go out of your way   
   >> to knowingly write incorrect code - prioritising tiny, irrelevant   
   >> savings in source code space over correct, guaranteed, portable code   
   >> that can be automatically checked by tools.   
   >   
   > Snipet from ClassGuidelines.txt   
   >    ...   
   >    wrd(or notation)   
   >            This function converts the argument object (a type, class,..) to   
   text   
   [SNIP]   
      
   > My reply might not be directly in the topic of current post. Just jumpped in   
   > to reply.   
      
   Huh??  "ClassGuideline.txt" (which I managed to find on Sourceforge)   
   is a set of guidelines for C++ programming, apparently something   
   you wrote.  As far as I can tell, it has nothing to do with the   
   current discussion or with the topic of this newsgroup.  Why did   
   you mention it here?   
      
   >           It looks to me the format character MUST match the type passed to    
   > printf, otherwise UB.   
      
   It doesn't just look to you that way.  The C standard says   
   so explicitly.  C17 and earlier says "If any argument is not   
   the correct type for the corresponding conversion specification,   
   the behavior is undefined."  C23 changed the wording, saying that   
   fprintf shall behave as if it uses va_arg; the description of va_arg   
   says the behavior is undefined if the wrong type is used.   
      
   Note that the description of va_arg allows, for example, using   
   unsigned int for an argument of type int or vice versa *if* the   
   value is within the range of both.  If it had been the intent to   
   allow incompatible types that happen to have the same size and   
   representation, the standard would have said so.   
      
   --   
   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