snprintf() confusion
Posted Feb 5, 2004 6:02 UTC (Thu) by
IkeTo (subscriber, #2122)
Parent article:
snprintf() confusion
I think the convention that sprintf returns the number of bytes written (rather than "would be written") does not make a real lot of sense: you never know whether your buffer is large enough, so there is no way to inform the user that something is truncated. And even if you guess it is not (because buffer size == return value), you have no way to allocate the required memory size. Given that most programmers won't even use snprintf, I think that educating those who are already better off should be easy: all they need is to use the min of the returned value and the buffer size if they want the scnprintf semantics.
(
Log in to post comments)