home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 116,450 of 117,927   
   Paul Rubin to dxf   
   Re: Numeric string output - conspicuousl   
   01 May 24 21:41:53   
   
   From: no.email@nospam.invalid   
      
   dxf  writes:   
   > Perhaps implementations vary.  Subsequent to my question I remembered   
   > I had the source for a 'small-C' for CP/M.  Looking at the primitive for   
   > sprintf I found it uses a small static buffer.  The numeric string is   
   > built there after which it's copied to the user-designated buffer.   
      
   sprintf(buf, "%d", n) still works.  It's like snprintf except the buffer   
   size is not specified.  The buffer is instead assumed to be large enough   
   to hold the output.  That can obviously be dangerous, especially   
   considering %s for formatting strings, so snprintf is preferred.   
      
   Using a static buffer creates obvious thread safety issues if two calls   
   to sprintf are active at the same time.  The Linux man page for sprintf   
   and friends has the thread safety attribute "MT-Safe locale" for those   
   functions.  I don't know what that means exactly though.  In CP/M this   
   probably wasn't an issue.   
      
   --- 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